account.sendTransaction()
Send a transaction and wait for the receipt.
Type: instance async
Signature
async sendTransaction(calls: TransactionCall[]): Promise<Hash>Parameters
calls
Type: TransactionCall[]
Array of transaction calls to execute.
interface TransactionCall {
/** Target contract address */
to: Address;
/** Value to send in wei (bigint or hex string) */
value?: bigint | string;
/** Call data */
data?: Hex;
}Returns
Promise<Hash> - The transaction hash after the transaction is included in a block.
Value Format
The value field must be in wei (the smallest unit of ETH):
import { parseEther } from 'viem';
// BigInt (wei)
{ to: '0x...', value: 1000000000000000000n } // 1 ETH in wei
// Hex string (wei)
{ to: '0x...', value: '0x0de0b6b3a7640000' } // 1 ETH in wei
// Using parseEther for convenience
{ to: '0x...', value: parseEther('1') } // 1 ETH
{ to: '0x...', value: parseEther('0.1') } // 0.1 ETHExample
Getting an Account Instance
Before calling instance methods, create an account using one of the factory methods:
import { Account } from '@jaw.id/core';
// Option 1: Restore existing session or login with passkey
const account = await Account.get({ chainId: 1, apiKey: 'your-api-key' });
// Option 2: Create a new account with passkey
const account = await Account.create(
{ chainId: 1, apiKey: 'your-api-key' },
{ username: 'alice' }
);
// Option 3: Import from cloud backup
const account = await Account.import({ chainId: 1, apiKey: 'your-api-key' });
// Option 4: From a local account (server-side / embedded wallets)
const account = await Account.fromLocalAccount(
{ chainId: 1, apiKey: 'your-api-key' },
localAccount
);Send ETH
import { parseEther } from 'viem';
// Send 0.1 ETH
const hash = await account.sendTransaction([
{ to: '0xRecipient...', value: parseEther('0.1') }
]);
console.log('Transaction hash:', hash);Contract Call
import { encodeFunctionData } from 'viem';
// Encode the function call
const data = encodeFunctionData({
abi: erc20Abi,
functionName: 'transfer',
args: ['0xRecipient...', 1000000n], // 1 USDC (6 decimals)
});
const hash = await account.sendTransaction([
{ to: USDC_ADDRESS, data }
]);Related
- account.sendCalls() - Send without waiting for receipt
- account.estimateGas() - Estimate gas before sending