Documentation Index
Fetch the complete documentation index at: https://www.dynamic.xyz/docs/llms.txt
Use this file to discover all available pages before exploring further.
Use signTransaction on a Viem WalletClient to produce a signed, serialized transaction without submitting it. This is useful when you need to:
- Hand the signed transaction to a relayer or sponsor service for submission.
- Co-sign a multi-step flow before broadcasting atomically.
- Inspect or store the raw signed bytes before sending.
Usage
import { parseEther } from 'viem';
import { createWalletClientForWalletAccount } from '@dynamic-labs-sdk/evm/viem';
const signTransaction = async (walletAccount) => {
const walletClient = await createWalletClientForWalletAccount({ walletAccount });
const signedTx = await walletClient.signTransaction({
to: '0x0000000000000000000000000000000000000000',
value: parseEther('0.05'),
});
console.log('signed transaction:', signedTx);
return signedTx;
};
import { parseEther } from 'viem';
import { createWalletClientForWalletAccount } from '@dynamic-labs-sdk/evm/viem';
import { isEvmWalletAccount } from '@dynamic-labs-sdk/evm';
import { useWalletAccounts } from '@dynamic-labs-sdk/react-hooks';
function SignTransactionButton() {
const walletAccounts = useWalletAccounts();
const walletAccount = walletAccounts.find(isEvmWalletAccount);
const handleSign = async () => {
if (!walletAccount) return;
const walletClient = await createWalletClientForWalletAccount({ walletAccount });
const signedTx = await walletClient.signTransaction({
to: '0x0000000000000000000000000000000000000000',
value: parseEther('0.05'),
});
console.log('signed transaction:', signedTx);
};
return (
<button onClick={handleSign} disabled={!walletAccount}>
Sign transaction
</button>
);
}
Submitting later
The output of signTransaction is a serialized, signed transaction (hex). When you’re ready to broadcast it, send it through any RPC — for example, with a Viem PublicClient:
import { createPublicClientFromNetworkData } from '@dynamic-labs-sdk/evm/viem';
import { getActiveNetworkData } from '@dynamic-labs-sdk/client';
const { networkData } = await getActiveNetworkData({ walletAccount });
const publicClient = createPublicClientFromNetworkData({ networkData });
const txHash = await publicClient.sendRawTransaction({
serializedTransaction: signedTx,
});
Notes
- The wallet account must be an EVM account. Narrow the type with
isEvmWalletAccount before calling createWalletClientForWalletAccount.
- Some wallet apps refuse to sign without broadcasting — they will surface a user-rejection error in that case. Check the wallet’s UX expectations before relying on this flow in production.
- Signing uses the wallet’s currently active chain. Switch first with
switchActiveNetwork if you need a different one.
- Need to estimate fees before signing? See Calculate EVM transaction fee.