๐Ÿ‘ฉโ€๐Ÿ’ป
Galactica Network Dev Documentation
  • ๐Ÿ“™Galactica Network Overview
  • ๐ŸงฌGalactica Concepts
    • โ›“๏ธBlockchain Base
    • ๐ŸงพZero-Knowledge KYC
      • Holder Commitment
      • DApp specific HumanID
      • Verification SBT
      • KYC Guardian
      • Galactica Investigation Module
      • Privacy Precautions
    • ๐ŸŒŸReputation
    • ๐Ÿ›‚Contingent Transactions
  • โš™๏ธGalactica Components
    • ๐ŸฆŠGalactica Snap for Metamask
    • ๐ŸŒณRoot Contracts
  • ๐Ÿ—๏ธBuilding a Galactica DApp
    • Example DApps
      • Compliant ERC20
      • Cypherbook
      • Compliant DEX
      • Sybil resistant airdrop
    • Front End
      • Guided Example
        • Connect to Galactica Snap
        • Prepare ZK proof generation
        • Generate and submit ZK proof
        • Handle Verification SBTs
      • Galactica Snap JSON-RPC API
    • Smart Contracts
    • Custom Zero Knowledge Disclosures
  • ๐Ÿ“Guardian Guide
    • Setup to become a Guardian
    • Create and issue ZK certificate
      • ๐ŸชชzkKYC (GIP-1)
      • Arbitrary ZK data certificate (GIP-2)
      • X/Twitter ZK certificate (GIP-3)
      • REY X/Twitter Score ZK certificate (GIP-4)
      • Decentralised Exchange (DEX) ZK certificate (GIP-5)
      • Centralised Exchange (CEX) ZK certificate (GIP-6)
      • Telegram ZK certificate (GIP-7)
  • โ›๏ธValidator Guide
    • ๐Ÿ”งInstallation
    • ๐Ÿ”—Become a Validator
    • ๐Ÿš€galacticad CLI Usage Cheat Sheet
    • ๐Ÿ”’Security Best Practices
  • ๐ŸงชTestNet: Reticulum
    • Release Notes
  • ๐ŸงชDevNet: Andromeda
    • Release Notes
  • ๐Ÿ“ŽChangelog
Powered by GitBook
On this page

Was this helpful?

  1. Building a Galactica DApp
  2. Front End
  3. Guided Example

Connect to Galactica Snap

PreviousGuided ExampleNextPrepare ZK proof generation

Last updated 1 year ago

Was this helpful?

Before the Galactica Snap can be installed, we need to check that Metamask is available in the user's browser. This is similar to a .

If Metamask is not installed, you can forward the user with the connect button to the install page:

export const InstallMetamaskButton = () => (
  <Link href="https://metamask.io/" target="_blank">
    <FlaskFox />
    <ButtonText>Install MetaMask</ButtonText>
  </Link>
);

With Metamask present, the user can connect to the Galactica Snap and install it if necessary (missing or outdated) with the following function:

const defaultSnapOrigin = "npm:@galactica-corp/snap";

await window.ethereum.request({
  method: 'wallet_requestSnaps',
  params: {
    [defaultSnapOrigin]: {},
  },
});

You can verify if the Snap is installed:

/**
 * Get the snap from MetaMask.
 *
 * @returns The snap object returned by the extension.
 */
export const getSnap = async (): Promise<Snap | undefined> => {
  try {
    const snaps = await window.ethereum.request({
      method: 'wallet_getSnaps',
    });

    return Object.values(snaps).find(
      (snap) => snap.id === defaultSnapOrigin,
    );
  } catch (error) {
    console.log('Failed to obtain installed snap', error);
    return undefined;
  }
};

Now you should be able to use Galactica specific functions through the snap using the . See the next page for an example

๐Ÿ—๏ธ
standard Metamask connection
wallet_invokeSnap method