SVG Definitions

Deploy Contracts

Deploy Solidity contracts from a smart account using account abstraction.

Deploying a contract with a smart account uses the same EVM rules as an EOA deployment, but the transaction is wrapped in a UserOperation. You encode the deployment init code with encodeDeployData, then send it through the smart account client. The contract is created from the smart account address, so the smart account is the deployer.


Understanding deployments with smart accounts

Contract creation happens when the transaction payload contains init code instead of a to address. encodeDeployData builds that init code from your contract ABI, bytecode, and constructor args. The smart account client packages this into a UserOperation, and the bundler submits it on-chain. If you configure a paymaster, gas can be sponsored; otherwise the smart account pays gas normally.

The deployed address is derived from the smart account and its nonce, just like EOA deployments. If you need a deterministic address, you should deploy via a CREATE2 factory, but the flow below covers the standard CREATE-based deployment path.


Usage

index.ts
import { encodeDeployData } from "viem";
import { CounterAbi, CounterBytecode } from "./contract";
import { publicClient, smartAccountClient } from "./clients";

const deployData = encodeDeployData({
  abi: CounterAbi,
  args: [1n],
  bytecode: CounterBytecode,
});

const txHash = await smartAccountClient.sendTransaction({
  callData: deployData,
});

console.log({
  txHash,
  deployer: smartAccountClient.account.address,
  chainId: publicClient.chain.id,
});

Examples

Deploy with a different constructor value

Change the constructor args to set the initial state at deployment time.

const deployData = encodeDeployData({
  abi: CounterAbi,
  args: [42n],
  bytecode: CounterBytecode,
});

const txHash = await smartAccountClient.sendTransaction({
  callData: deployData,
});

Use compiled artifacts

If you compile with Foundry or Hardhat, you can feed the JSON artifact directly into encodeDeployData.

import CounterArtifact from "./Counter.json";

const deployData = encodeDeployData({
  abi: CounterArtifact.abi,
  args: [1n],
  bytecode: CounterArtifact.bytecode,
});

References