Skip to content

sendTransaction

Send a transaction from a smart account using the same sendTransaction interface as viem.

Internally, sendTransaction calls the smartAccount's prepareUserOperation, sendUserOperation, and waitForUserOperationReceipt actions.

Usage

example.ts
import { smartAccountClient, simpleSmartAccount } from "./smartAccountClient"
import { parseAbiItem, encodeFunctionData } from "viem"
 
const hash = await smartAccountClient.sendTransaction({
    to: "0x0488bEE1Ec682db0F0E74AB52faFdDdEf10Af123",
    data: encodeFunctionData({
        abi: [parseAbiItem('function mint()')]
    }),
    value: 0n
})

You could also use the sendTransaction method to send multiple transactions in a single batch like so:

const hash = await smartAccountClient.sendTransaction({
    calls: [
        {
            to: "0x0488bEE1Ec682db0F0E74AB52faFdDdEf10Af123",
            data: encodeFunctionData({
                abi: [parseAbiItem('function mint()')]
            }),
            value: 0n
        },
        {
            to: "0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc",
            abi: [{"inputs":[],"name":"getLastGreeter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"greet","outputs":[],"stateMutability":"nonpayable","type":"function"}],
            functionName: "greet",
            args: [],
        }
    ]
})

Returns

  • Type: Hash

The transaction hash of the mined userOperation

Parameters

account

  • Type: SmartAccount

The Account to use for User Operation execution.

import { account, smartAccountClient } from './config'
import { parseEther } from 'viem'
const hash = await smartAccountClient.sendTransaction({
  account, 
  calls: [{
    to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
    value: parseEther('1')
  }]
})

calls

  • Type: ({ data?: Hex | undefined, to: Address, value?: bigint | undefined } | { abi: Abi, functionName: string, args: unknown[], to: Address, value?: bigint | undefined })[]

The calls to execute in the User Operation.

import { account, smartAccountClient } from './config'
import { parseEther } from 'viem'
const hash = await smartAccountClient.sendTransaction({
  account,
  calls: [{ 
    to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', 
    value: parseEther('1') 
  }, { 
    abi: wagmiAbi, 
    functionName: 'mint', 
    to: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', 
  }] 
})

callGasLimit (optional)

  • Type: bigint

The amount of gas to allocate the main execution call.

import { account, smartAccountClient } from './config'
import { parseEther } from 'viem'
const hash = await smartAccountClient.sendTransaction({
  account,
  calls: [{
    to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
    value: parseEther('1')
  }],
  callGasLimit: 69420n, 
})

factory (optional)

  • Type: Address

Account Factory address.

import { account, smartAccountClient } from './config'
import { parseEther } from 'viem'
const hash = await smartAccountClient.sendTransaction({
  account,
  calls: [{
    to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
    value: parseEther('1')
  }],
  factory: '0x1234567890123456789012345678901234567890', 
  factoryData: '0xdeadbeef',
})

factoryData (optional)

  • Type: Hex

Call data to execute on the Account Factory to deploy a Smart Account.

import { account, smartAccountClient } from './config'
import { parseEther } from 'viem'
const hash = await smartAccountClient.sendTransaction({
  account,
  calls: [{
    to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
    value: parseEther('1')
  }],
  factory: '0x1234567890123456789012345678901234567890',
  factoryData: '0xdeadbeef', 
})

maxFeePerGas (optional)

  • Type: bigint

Maximum fee per gas for User Operation execution.

import { account, smartAccountClient } from './config'
import { parseEther } from 'viem'
const hash = await smartAccountClient.sendTransaction({
  account,
  calls: [{
    to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
    value: parseEther('1')
  }],
  maxFeePerGas: 420n, 
})

maxPriorityFeePerGas (optional)

  • Type: bigint

Maximum priority fee per gas for User Operation execution.

import { account, smartAccountClient } from './config'
import { parseEther } from 'viem'
const hash = await smartAccountClient.sendTransaction({
  account,
  calls: [{
    to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
    value: parseEther('1')
  }],
  maxPriorityFeePerGas: 420n, 
  maxFeePerGas: 10n, 
})

nonce (optional)

  • Type: bigint

Nonce for the User Operation.

import { account, smartAccountClient } from './config'
import { parseEther } from 'viem'
const hash = await smartAccountClient.sendTransaction({
  account,
  calls: [{
    to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
    value: parseEther('1')
  }],
  nonce: 10n, 
})

paymaster (optional)

  • Type: Address | true | PaymasterClient | PaymasterActions

Sets Paymaster configuration for the User Operation.

  • If paymaster: Address, it will use the provided Paymaster contract address for sponsorship.
  • If paymaster: PaymasterClient, it will use the provided Paymaster Client eg Pimlico Client for sponsorship.
  • If paymaster: true, it will be assumed that the Bundler Client also supports Paymaster RPC methods (e.g. pm_getPaymasterData), and use them for sponsorship.

Using a Paymaster Contract Address

import { account, smartAccountClient } from './config'
import { parseEther } from 'viem'
const hash = await smartAccountClient.sendTransaction({
  account,
  calls: [{
    to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
    value: parseEther('1')
  }],
  paymaster: '0x942fD5017c0F60575930D8574Eaca13BEcD6e1bB', 
  paymasterData: '0xdeadbeef',
})

Using a Paymaster Client

import { account, smartAccountClient } from './config'
import { parseEther } from 'viem'
const paymasterClient = createPaymasterClient({ 
  transport: http('https://api.pimlico.io/v2/1/rpc?apikey={API_KEY}') 
}) 
 
const hash = await smartAccountClient.sendTransaction({
  account,
  calls: [{
    to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
    value: parseEther('1')
  }],
  paymaster: paymasterClient, 
})

Using the Bundler Client as Paymaster

import { account, smartAccountClient } from './config'
import { parseEther } from 'viem'
const hash = await smartAccountClient.sendTransaction({
  account,
  calls: [{
    to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
    value: parseEther('1')
  }],
  paymaster: true, 
})

paymasterContext (optional)

  • Type: unknown

Paymaster specific fields.

import { account, smartAccountClient } from './config'
import { parseEther } from 'viem'
const paymasterClient = createPaymasterClient({
  transport: http('https://api.pimlico.io/v2/1/rpc?apikey={API_KEY}')
})
 
const hash = await smartAccountClient.sendTransaction({
  account,
  calls: [{
    to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
    value: parseEther('1')
  }],
  paymaster: paymasterClient,
  paymasterContext: { 
    policyId: 'abc123'
  }, 
})

paymasterData (optional)

  • Type: Address

Call data to execute on the Paymaster contract.

import { account, smartAccountClient } from './config'
import { parseEther } from 'viem'
const hash = await smartAccountClient.sendTransaction({
  account,
  calls: [{
    to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
    value: parseEther('1')
  }],
  paymaster: '0x942fD5017c0F60575930D8574Eaca13BEcD6e1bB',
  paymasterData: '0xdeadbeef', 
})

paymasterPostOpGasLimit (optional)

  • Type: bigint

The amount of gas to allocate for the Paymaster post-operation code.

import { account, smartAccountClient } from './config'
import { parseEther } from 'viem'
const hash = await smartAccountClient.sendTransaction({
  account,
  calls: [{
    to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
    value: parseEther('1')
  }],
  paymaster: '0x942fD5017c0F60575930D8574Eaca13BEcD6e1bB',
  paymasterData: '0xdeadbeef',
  paymasterPostOpGasLimit: 69420n, 
})

paymasterVerificationGasLimit (optional)

  • Type: bigint

The amount of gas to allocate for the Paymaster validation code.

import { account, smartAccountClient } from './config'
import { parseEther } from 'viem'
const hash = await smartAccountClient.sendTransaction({
  account,
  calls: [{
    to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
    value: parseEther('1')
  }],
  paymaster: '0x942fD5017c0F60575930D8574Eaca13BEcD6e1bB',
  paymasterData: '0xdeadbeef',
  paymasterVerificationGasLimit: 69420n, 
})

preVerificationGas (optional)

  • Type: bigint

Extra gas to pay the Bunder.

import { account, smartAccountClient } from './config'
import { parseEther } from 'viem'
const hash = await smartAccountClient.sendTransaction({
  account,
  calls: [{
    to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
    value: parseEther('1')
  }],
  preVerificationGas: 69420n, 
})

signature (optional)

  • Type: Hex

Signature for the User Operation.

import { account, smartAccountClient } from './config'
import { parseEther } from 'viem'
const hash = await smartAccountClient.sendTransaction({
  account,
  calls: [{
    to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
    value: parseEther('1')
  }],
  signature: '0x...', 
})

verificationGasLimit (optional)

  • Type: bigint

The amount of gas to allocate for the verification step.

import { account, smartAccountClient } from './config'
import { parseEther } from 'viem'
const hash = await smartAccountClient.sendTransaction({
  account,
  calls: [{
    to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
    value: parseEther('1')
  }],
  verificationGasLimit: 69420n, 
})

to (optional)

  • Type: 0x${string}

The transaction recipient or contract address.

data (optional)

  • Type: 0x${string}

A contract hashed method call with encoded args.

value (optional)

  • Type: bigint

Value in wei sent with this transaction.

maxFeePerGas (optional)

  • Type: bigint

Total fee per gas (in wei), inclusive of maxPriorityFeePerGas. Only applies to EIP-1559 Transactions.

maxPriorityFeePerGas (optional)

  • Type: bigint

Max priority fee per gas (in wei). Only applies to EIP-1559 Transactions.

nonce (optional)

  • Type: number

Unique number identifying this transaction.

account (optional)

  • Type: SmartAccount

The Account to send the transaction from.