Arbitrary Transactions

Execute any transaction interpretable by an EVM chain.

FunWallets can execute any transaction interpretable by an EVM chain by specifying the (to, data) parameters in the Ethereum transaction format. With FunWallet.execRawTx you can mint NFTs, approve token spends, and call any smart contract.

The arbitrary transactions feature enables FunWallets to be used as browser wallets, or mobile wallets.

Approve tokens to an external account

The following flow demonstrates how to give USDC token spend approval to DEST_ADDR on the Göerli testnet. We use ethers.js to create the transaction object.

const { FunWallet, configureEnvironment } = require("fun-wallet")
const { Eoa } = require("fun-wallet/auth")
const { Token } = require("fun-wallet/data")
const { fundWallet } = require("fun-wallet/utils")
const { Contract } = require("ethers")
const abi = require("fun-wallet/abis/ERC20.json").abi
// Replace these with your own
const PRIVATE_KEY = "0x98e9cfb323863bc4bfc094482703f3d4ac0cd407e3af2351c00dde1a6732756a"
const API_KEY = "MYny3w7xJh6PRlRgkJ9604sHouY2MTke6lCPpSHq"
const DEST_ADDR = "0x07Ac5A221e5b3263ad0E04aBa6076B795A91aef9"
const approve = async () => {
await configureEnvironment({
apiKey: API_KEY,
const auth = new Eoa({ privateKey: PRIVATE_KEY })
const tokenAddress = await Token.getAddress("usdc")
const provider = await global.chain.getProvider()
const contract = new Contract(tokenAddress, abi, provider)
const tx = await contract.populateTransaction.approve(TO_ADDR, 1e6)
// Get FunWallet associated with EOA
const uniqueId = await auth.getUniqueId()
const wallet = new FunWallet({ uniqueId })
// NOTE: Wallet must be prefunded if not using a sponsor
// await fundWallet(funder_auth, wallet, .005)
// auth: an auth object (see Auth API)
// tx: a ethereum formatted transaction object: see
await wallet.execRawTx(auth, tx)


  • Ensure your privateKey starts with '0x'.

  • Ensure your account has enough funds to transfer and pay for gas. (ie: USDC, ETH). See error AA21.

  • If the token used is not available, use the token address.