EVM Wallets
There are methods in the Ethereum wallet specific to EVM which we list below, but in general all the methods you need are present on the generic Wallet described here.
Check if a wallet is an Ethereum wallet
You can use the isEthereumWallet
helper method to check if a wallet is a Ethereum wallet. That way, TypeScript will know which methods are available to you.
import { isEthereumWallet } from '@dynamic-labs/ethereum';
if (!isEthereumWallet(wallet)) {
throw new Error('This wallet is not a Ethereum wallet');
}
const client = await primaryWallet.getWalletClient();
Ethereum Wallet Methods
Method | Description |
---|---|
getPublicClient(): Promise<PublicClient<Transport, Chain>> | Retrieves the public client. |
getWalletClient(chainId?: string): Promise<WalletClient<Transport, Chain, Account>> | Retrieves the wallet client. |
Read only actions
If you want to read data from the blockchain, you will want either a “Public Client” (Viem terminology), or a “Provider” (Ethers terminology). Both allow you read only access to the blockchain.
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
const { primaryWallet } = useDynamicContext();
const getEnsName = async () => {
const publicClient = await primaryWallet?.getPublicClient()
// Now you can use the public client to read data from the blockchain
const ens = await publicClient?.getEnsName({ address: primaryWallet.address })
return ens
}
Write actions
If you want to write data to the blockchain, you will need a “Wallet Client” (Viem terminology), or a “Signer” (Ethers terminology). Both allow you to sign transactions with the private key.
import { useDynamicContext } from '@dynamic-labs/sdk-react-core';
import { isEthereumWallet } from '@dynamic-labs/ethereum';
const { primaryWallet } = useDynamicContext();
const sendTransaction = async () => {
if(!primaryWallet || !isEthereumWallet(primaryWallet)) {
return;
}
const walletClient = await primaryWallet.getWalletClient();
// Now you can use the wallet client to write data to the blockchain
const tx = await walletClient?.sendTransaction({
to: '0x1234567890abcdef',
value: '1000000000000000000'
});
return tx
}
Examples
We’ve included a few examples of how to use the EVM wallet connector in this section:
Was this page helpful?