Documentation Index
Fetch the complete documentation index at: https://docs.dynamic.xyz/docs/llms.txt
Use this file to discover all available pages before exploring further.
Viem is one of the most popular libraries for interacting with EVM blockchains.
A WalletClient is an interface to interact with EVM accounts and provides the ability to retrieve accounts, execute transactions, sign messages, etc.
We provide a helper method to allow you to create a Viem WalletClient for a given wallet account.
Usage
import { createWalletClientForWalletAccount } from '@dynamic-labs-sdk/evm/viem';
const sendTransaction = async (walletAccount, transaction) => {
const walletClient = await createWalletClientForWalletAccount({
walletAccount,
});
const result = await walletClient.sendTransaction(transaction);
console.log('Transaction sent:', result);
// ...
};
Use useWalletAccounts to reactively get the wallet, then call createWalletClientForWalletAccount inside an event handler:import { createWalletClientForWalletAccount } from '@dynamic-labs-sdk/evm/viem';
import { useWalletAccounts } from '@dynamic-labs-sdk/react-hooks';
function SendTransactionButton({ transaction }) {
const walletAccounts = useWalletAccounts();
const walletAccount = walletAccounts[0];
const handleSend = async () => {
if (!walletAccount) return;
const walletClient = await createWalletClientForWalletAccount({ walletAccount });
const result = await walletClient.sendTransaction(transaction);
console.log('Transaction sent:', result);
};
return (
<button onClick={handleSend} disabled={!walletAccount}>
Send Transaction
</button>
);
}