Connect

Connect with Metamask

Before you can create a payment system or send any transaction you need to connect with the web3-provider. For that reason we made it as easy as possible to connect over the Palindrome SDK with Metamask.


connectMetamask

Call the connectMetamask(args) function to connect with Metamask over Desktop Computer.Palindrome Crypto Payment is supporting multiple chains such as AVAX, Ethereum & BSC. Therefore, you need to pass the chainID or rpc with chainID so that thePalindrome Crypto Pay Crypto SDK can recognize the chain you want to work with.

Import Functions

In the first step you need to import thePalindrome Crypto Pay SDK into your JavaScript/TypeScript project with the needed function PalindromePayConnect.

import { PalindromePayConnect } from '@Palindromepay/sdk'

Interfaces

// Input
export interface IConnect {
  rpc?: { [chainId: number]: string }; // optional
  chainId: number;
}

// Output
export interface IAuthInstance {
  account: string;
  provider: any;
  signer: any;
}

Function

PalindromePayConnect.connectMetamask(args)

Params

NameTypeDescription
rpc (Optional)ObjectPass Object which includes the chainID and rpc-url
chainIDnumberPass the chainID of the network

Example Code

try {
  loginMetamask = async () => {
    const args: IConnect = {
      rpc: { 43114: 'https://api.avax.network/ext/bc/C/rpc' },
      chainId: 43114,
    }
    const auth: IAuthInstance = await PalindromePayConnect.connectMetamask(args)
    if (!auth?.account) {
      console.log('Logged in failed...')
    } else {
      console.log('Logged in succeed...')
    }
  }
} catch (e) {
  console.log(e)
}
Previous
Getting started