Connect to Web3 Wallet

Use this method to allow users to login via Metamask or WalletConnect.

Import Metamask

import { MetamaskConnector } from "@altura/altura-js/lib/connector";

const wallet = new MetamaskConnector(window.ethereum);

wallet.connect(); // connect to the wallet

Import WalletConnect

First install WalletConnect web3-provider :

npm i @walletconnect/web3-provider

Now import WalletConnect web3-provider and WalletConnectConnector from Altura:

import { WalletConnectConnector } from "@altura/altura-js/lib/connector";
import WalletConnectProvider from "@walletconnect/web3-provider";

Now, instantiate your WalletConnect web3-provider using the following options: Infura or Custom RPC mapping

import WalletConnectProvider from "@walletconnect/web3-provider";

//  Create WalletConnect Provider
const provider = new WalletConnectProvider({
  infuraId: "27e484dcd9e3efcfd25a83a78777cdf1",

//  Enable session (triggers QR Code modal)
await provider.enable();

Now integrate it with WalletConnectConnector:

const wallet = new WalletConnectConnector(provider);

Get Wallet Address

const walletAddress = await wallet.address();

Get Wallet Balance

const walletAddress = await wallet.address();

Sign Message

try {
    await wallet.sign("Hi Altura!");
} catch (error) {
    console.log("Denied the sign", error);

Send Transaction

try {
    const tx = {
        to: "0x4976fb03C32e5B8cfe2b6cCB31c09Ba78EBaBa41",
        // `function addr(namehash("ricmoo.eth")) view returns (address)`
        data: "0x3b3b57debf074faa138b72c65adbdcfb329847e4f2c04bde7f7dd7fcad5a52d2f395a558",
    await wallet.sendTransaction(tx);
} catch (error) {
    console.log("Error on sending transaction", error);

Get Network information

const getNetworkData = await wallet.getNetwork();

Get Gas Price

const getGasPrice = await wallet.getGasPrice();

Get Fee Data

const getFeeData = await wallet.getFeeData();

Get Block Number

const getBlockNumber = await wallet.getBlockNumber();

Last updated