EVM Interactions
Send a transaction on Ethereum/EVM
Configurations
- Installing Dynamic
- Chains/Networks
- Authentication
- Wallets
- Set Up Embedded Wallets
- Set Up Global Connectivity
- Set Up Branded Wallets
- Add Account Abstraction
- Using Wallets
- Accessing Wallets
- Interacting with wallets
- General Interactions
- EVM Interactions
- Bitcoin Interactions
- Solana Interactions
- Multi Wallet
- Multi Asset UI
- Send Balance UI
- Users / VC's
- Design
- Headless
- Onramps
- Bridges
Developer Dashboard
- SDK and API Keys
- Sandbox vs Live
- Analytics
- User Management
- Settings
- Admin
- Webhooks
- Configuring Social Providers
Tutorials
- Farcaster
- Features
- Frameworks
- Integrations
- Webhooks
Migrating to Dynamic
- Migrating to Dynamic
- Migration Tutorials
SDKs
- React SDK
Troubleshooting
- Dynamic Doctor
- React Issues
- NextJS Issues
- Wallet Issues
- WalletConnect Issues
- Solved Issues
EVM Interactions
Send a transaction on Ethereum/EVM
import { FC, FormEventHandler, useState } from "react";
import {
Account,
Chain,
Hex,
Transport,
WalletClient,
PublicClient,
parseEther,
} from "viem";
import { useDynamicContext } from "@dynamic-labs/sdk-react-core";
import { getChain } from "@dynamic-labs/utils";
export const SendTransactionSection: FC = () => {
const { primaryWallet } = useDynamicContext();
const [txnHash, setTxnHash] = useState("");
if (!primaryWallet) return null;
const onSubmit: FormEventHandler<HTMLFormElement> = async (event) => {
event.preventDefault();
const formData = new FormData(event.currentTarget);
const address = formData.get("address") as string;
const amount = formData.get("amount") as string;
const provider = await primaryWallet.getSigner();
if (!provider) return;
const transaction = {
account: primaryWallet.address as Hex,
chain: getChain(await provider.getChainId()),
to: address as Hex,
value: amount ? parseEther(amount) : undefined,
};
const hash = await provider.sendTransaction(transaction);
const client =
await primaryWallet.getPublicClient();
const { transactionHash } = await client.getTransactionReceipt({
hash,
});
setTxnHash(transactionHash);
};
return (
<form onSubmit={onSubmit}>
<p>Send to ETH address</p>
<input name="address" type="text" required placeholder="Address" />
<input name="amount" type="text" required placeholder="0.05" />
<button type="submit">Send</button>
<span data-testid="transaction-section-result-hash">{txnHash}</span>
</form>
);
};
Was this page helpful?