Wallet Integration
Implementation Checklist
The integration implementation checklist for dApp developers consists of three categories:
Frontend features
Transactions and wallet interactions
Client-side provider
Frontend
Make sure to create a wallet-connection button for Metamask and/or Keplr on the frontend of the application. For instance, consider the "Connect to a wallet" button on the interface of Diffusion Finance.
Transactions
Developers enabling transactions on their dApp have to determine wallet type of the user, create the transaction, request signatures from the corresponding wallet, and finally broadcast the transaction to the network.
Determining Wallet Type
Developers should determine whether users are using Keplr or MetaMask. Whether MetaMask or Keplr is installed on the user device can be determined by checking the corresponding window.ethereum
or window.keplr
value.
For MetaMask:
await window.ethereum.enable(chainId);
For Keplr:
await window.keplr.enable(chainId);
If either window.ethereum
or window.keplr
returns undefined
after document.load
, then MetaMask (or, correspondingly, Keplr) is not installed. There are several ways to wait for the load event to check the status: for instance, developers can register functions to window.onload
, or they can track the document's ready state through the document event listener.
After the user's wallet type has been determined, developers can proceed with creating, signing, and sending transactions.
Create the Transaction
The example below uses the BlockX Testnet chainID
. For more info, check the BlockX Chain IDs reference document here.
Developers can create MsgSend
transactions.
Sign and Broadcast the Transaction
The example below uses an BlockX Testnet RPC node.
After creating the transaction, developers need to send the payload to the appropriate wallet to be signed (msg.signDirect
is the transaction in Keplr format, and msg.eipToSign
is the EIP712
data to sign with MetaMask).
Connections
For Ethereum RPC, BlockX gRPC, and/or REST queries, dApp developers should implement providers client-side, and store RPC details in the environment variable as secrets.
Last updated