Skip to main content

Interacting Onchain

With an Address, you can quickly get a Viem Account that can be used to sign transactions and messages.

In the following example, you can use getWalletClient(address) to get a walletClient that works with all of your Viem operations.

import { toViem } from "@coinbase/waas-sdk-viem";
import { Address } from '@coinbase/waas-sdk-web';
import { baseMainnet } from 'viem/chains'
import { createWalletClient, http} from 'viem';

// given a Waas Address, return a walletClient for use with viem.
const getWalletClient = async (address: Address) => {
return createWalletClient({
chain: baseMainnet,
transport: http(),
account: toViem(address) // toViem(..) produces a viem-compatible LocalAccount.
})
}
info

For more examples of what you can do onchain, see the Viem documentation.

Was this helpful?