TransactionsSend transactions

Send transactions

This guide will teach you how to send a single EVM transaction. Smart Wallets make it easy!

Prerequisites

Implementation

Required SDK version: ^v4.54.0

See the sendCalls SDK reference for full descriptions of the parameters used in the following example.

You can send transactions using the smart wallet client sendCalls action.

1import { parseEther, toHex } from "viem";
2import { client } from "./client.ts";
3
4const { preparedCallIds } = await client.sendCalls({
5 calls: [
6 {
7 to: "0x0000000000000000000000000000000000000000",
8 value: toHex(parseEther("0")),
9 data: "0x",
10 },
11 ],
12});
13
14console.log({ preparedCallIds });
15
16const result = await client.waitForCallsStatus({ id: preparedCallIds[0] });
17
18console.log(result);

Advanced

If you need to encode function data (instead of just sending value), it is easy to do so using Viem or Foundry.

In JavaScript, you can use Viem to encode function call data.

1import { encodeFunctionData } from "viem";
2import { client } from "./client.ts";
3import { exampleAbi } from "./abi.ts";
4
5await client.sendCalls({
6 calls: [
7 {
8 to: "0x0000000000000000000000000000000000000000",
9 data: encodeFunctionData({
10 abi: exampleAbi,
11 functionName: "mintTo",
12 args: [client.account!.address],
13 }),
14 },
15 ],
16});

Instead of using the sendCalls abstraction, you can prepare and send calls using underlying methods. Usage of the capability will be the same as when using send calls. It is recommended to use prepareCalls if you want to inspect the prepared call prior to prompting the user for signature.

Required SDK version: ^v4.54.0

You can use smart wallet client actions to prepare, sign, and send transactions.

1import { parseEther, toHex } from "viem";
2import { client } from "./client.ts";
3
4const preparedCalls = await client.prepareCalls({
5 calls: [
6 {
7 to: "0x0000000000000000000000000000000000000000",
8 value: toHex(parseEther("0")),
9 data: "0x",
10 },
11 ],
12});
13
14console.log({ preparedCalls }); // Here you can inspect the prepared calls before signing.
15
16const signedCalls = await client.signPreparedCalls(preparedCalls);
17
18const sentCalls = await client.sendPreparedCalls(signedCalls);
19
20console.log({ sentCalls });

See the prepareCalls, signPreparedCalls, and sendPreparedCalls SDK reference for full descriptions of the parameters used in the above example.

Next steps

Build more:

Troubleshooting: