Skip to content
function sendTransaction(ctx, params): Promise<`0x${string}`>;

Sends a transaction via the configured walletClient.

The pattern for write transactions is to use a strongly-typed function to create the transaction payload and rely on this function to [sign and] send the transaction. This approach allows transaction payloads to easily be wrapped for use in governance proposals, multisigs, and/or any other form of wrapped transaction execution.

Building and sending use two different clients, so the wallet’s chain is checked live against what the payload was built for before anything is submitted. Without that, a publicClient and profile on one network can produce an address and calldata that a wallet on another network signs and broadcasts — the address exists there too, holding different code, and any attached value (the Pyth update fee on oracle-dependent transactions) goes with it. viem does not close this: it asserts the wallet matches walletClient.chain, which says nothing about the chain the payload was built for, and for a local (private-key) account it skips even that.

Parameters

ParameterTypeDescription
ctxSDKContextThe SDK context.
paramsSendTransactionParamsThe transaction payload to sign and send.

Returns

Promise<`0x${string}`>

The hash of the transaction that was sent.

Throws

ProviderConnectionError If the client fails to connect to the provider. When the send call itself raised it, the wallet may have broadcast the transaction before the connection dropped, so check wallet activity before resending; the thrown error carries no public marker for that distinction, which the SDK’s workflow executor records as an Indeterminate operation with no transactionHash.

Throws

TransactionRevertError If the submitted transaction reverts.

Throws

UserRejectedRequestError If the user rejects the transaction in the connected wallet.

Throws

ConfigError If the connected wallet is on a different chain than the transaction was built for, or than the required profile.

Throws

WalletNotConnectedError If there is no connected wallet.

Example

// Every write follows build -> send -> await. Here: revoke the vault's
// USDC allowance.
const transaction = await buildERC20RevokeTransaction(sdk, {
erc20Address: USDC,
spender: await sdk.getContractAddress(AnvilContract.CollateralVault),
});
// Throws on wallet rejection, revert, or missing wallet.
const hash = await sendTransaction(sdk, { transaction });
const result = await awaitTransactionConfirmation(
sdk,
{ hash, confirmations: 2 },
AnvilWalletOperationType.ERC20Approve // selects the typed error below
);
if (result.error) throw new Error(JSON.stringify(result.error));
return result.receipt?.status === 'success';