EVM Interactions
Send a transaction on Ethereum/EVM
Configurations
- Installing Dynamic
- Chains/Networks
- Authentication
- Wallets
- Setup Embedded Wallets
- Setup Branded Wallets
- Add Account Abstraction
- Using Wallets
- Accessing Wallets
- Connecting Wallets
- Interacting with wallets
- General Interactions
- EVM Interactions
- Bitcoin Interactions
- Solana Interactions
- Multi Asset 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
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.connector.getSigner<
WalletClient<Transport, Chain, Account>
>();
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.connector.getPublicClient<PublicClient>();
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?