Skip to content

WalletConnect‐Polkadot

Thiendekaco edited this page Apr 4, 2024 · 2 revisions

@subwallet-connect/walletconnect-polkadot

Wallet module for connecting Wallet Connect Substrate to SubConnect

Install

npm i @subwallet-connect/core @subwallet-connect/walletconnect-polkadot

Options

type WalletConnectOptions = {
  /**
   * Project ID associated with [WalletConnect account](https://cloud.walletconnect.com)
   */
  projectId: string
  /**
   * Defaults to `appMetadata.explore` that is supplied to the SubConnect init
   * Strongly recommended to provide atleast one URL as it is required by some wallets (i.e. MetaMask)
   * To connect with walletconnect
   */
  dappUrl?: string
  /**
   * List of Required Chain(s) genesis hash for wallets to support in hex format
   * Defaults to ['0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3'] - Polkadot
   */
  requiredChains?: number[] | undefined
  /**
   * List of Optional Chain(s) genesis hash for wallets to support in hex format  
   * Defaults to the chains provided within the SubConnect init chain property
   */
  optionalChains?: number[] | undefined
  /**
   * `undefined` by default, see https://docs.walletconnect.com/2.0/web/walletConnectModal/options
   */
  qrModalOptions?: EthereumProviderOptions['qrModalOptions']
  /**
   * Additional required methods to be added to the default list of ['polkadot_signTransaction', 'polkadot_signMessage', 'polkadot_sendTransaction',
    'polkadot_getBalance','polkadot_requestAccounts']

   * Passed methods to be included along with the defaults methods - see https://docs.walletconnect.com/2.0/advanced/providers/ethereum#required-and-optional-methods
   */
  additionalRequiredMethods?: string[] | undefined
  /**
   * Additional required methods to be added to the default list of ['polkadot_signTransaction', 'polkadot_signMessage', 'polkadot_sendTransaction',
    'polkadot_getBalance','polkadot_requestAccounts']
   * Passed methods to be included along with the defaults methods - see https://docs.walletconnect.com/2.0/web/walletConnectModal/options
   */
  additionalOptionalMethods?: string[] | undefined
  /**
   * Optional function to handle WalletConnect URI when it becomes available
   */
  handleUri?: (uri: string) => Promise<unknown>
)

Usage

import Onboard from '@subwallet-connect/core'
import walletConnectModule from '@subwallet-connect/walletconnect-polkadot'

const wcInitOptions = {
  /**
   * Project ID associated with [WalletConnect account](https://cloud.walletconnect.com)
   */
  projectId: 'abc123...',
  /**
   * Chains required to be supported by all wallets connecting to your DApp
   */
  dappUrl: 'http://YourAwesomeDapp.com'
}

// initialize the module with options
const walletConnect = walletConnectModule(wcInitOptions)

// can also initialize with no options...

const onboard = Onboard({
  // ... other Onboard options
  wallets: [
    walletConnect
    //... other wallets
  ]
})

const connectedWallets = await onboard.connectWallet()

// Assuming only wallet connect is connected, index 0
// `instance` will give insight into the WalletConnect info
// such as namespaces, methods, chains, etc per wallet connected
const { instance } = connectedWallets[0]

console.log(connectedWallets)
Clone this wiki locally