web3-react-v8

Full Example

https://github.com/sodiumlabs/demo-dapp-web3-react

import { initializeConnector, Web3ReactHooks } from '@web3-react/core'
import { Connector } from '@web3-react/types'

// https://github.com/sodiumlabs/demo-dapp-web3-react/blob/main/src/connectors/sodium.ts
import { SodiumConnector } from './sodium'

export enum ConnectionType {
  SODIUM = 'SODIUM',
}

export interface Connection {
  connector: Connector
  hooks: Web3ReactHooks
  type: ConnectionType
}

const [web3Sodium, web3SodiumHooks] = initializeConnector<SodiumConnector>(
  (actions) =>
    new SodiumConnector({
      actions,
      config: {
        defaultNetworkId: 80001,
        walletAppURL: 'https://sodium-two.vercel.app',
        transports: {
          iframeTransport: {
            enabled: true,
          }
        },
      },
    })
)
export const sodiumConnection: Connection = {
  connector: web3Sodium,
  hooks: web3SodiumHooks,
  type: ConnectionType.SODIUM,
}


// connect
sodiumConnection.connector.activate();


// get provider
const provider = sodiumConnection.hooks.useProvider();

// signer
const signer = await provider!.getSigner()

// sign
const sig = await signer.signMessage(message)
console.log('signature:', sig)

Last updated