Send Transaction

Send Transaction

You can send a transaction to the network by calling the sendTransaction method. This method takes a TransactionRequest as a parameter.

Note that rpcURL field must be set in the initConfig method, if your connected network is not Ethereum or Polygon.

import { Address, parseEther } from 'viem'
import { sendTransaction } from '@joyid/evm';
interface Props {
  address: Address | null;
const SendTransaction = ({ address }: Props) => {
  const [toAddress, setToAddress] = React.useState(
  const [amount, setAmount] = React.useState("0.01");
  const onSign = async () => {
    const value = parseEther(amount);
    const txhash = await sendTransaction(
        to: toAddress,
        value: value.toString(),
    alert(`tx hash: ${txhash}`);
  return address ? (
    <div className="w-full">
      <h2 className="mb-4 text-lg text-center">Send Transaction</h2>
      <label className="label">To Address:</label>
        className="input input-bordered w-full mb-4"
        onChange={(e) => setToAddress(}
      <label className="label">Amount:</label>
        className="input input-bordered w-full mb-4"
        onChange={(e) => setAmount(}
      <button className="btn btn-primary" onClick={onSign}>
      <div className="divider"></div>
  ) : null;

Sign Transaction

If you prefer to sign a transaction but not send it to the network, you can use the signTransaction method. signTransaction method takes a TransactionRequest as a parameter and returns a signed serialized transaction.

import { signTransaction } from '@joyid/evm'
function signTx(address) {
  const tx = await signTransaction(
      to: '0xA6eBeCE9938C3e1757bE3024D2296666d6F8Fc49',
      value: '10000000000000000',
  // you can call rpc method `eth_sendRawTransaction` to send the transaction to the network:
  // await walletClient.sendRawTransaction(tx)

API Reference

Try it out