The AbstractClient includes a deployContract method that can be used to deploy a smart contract from the connected Abstract Global Wallet. It extends the deployContract function from Viem to include options for contract deployment on Abstract.

Usage

import { useAbstractClient } from "@abstract-foundation/agw-react";
import { erc20Abi } from "viem"; // example abi
import { abstractTestnet } from "viem/chains";

export default function DeployContract() {
    const { data: agwClient } = useAbstractClient();

    async function deployContract() {
        if (!agwClient) return;

        const hash = await agwClient.deployContract({
            abi: erc20Abi, // Your smart contract ABI
            account: agwClient.account,
            bytecode: "0x...", // Your smart contract bytecode
            chain: abstractTestnet,
            args: [], // Constructor arguments
        });
    }
}

Parameters

abi
Abi
required
The ABI of the contract to deploy.
bytecode
string
required
The bytecode of the contract to deploy.
account
Account
required
The account to deploy the contract from. Use the account from the AbstractClient to use the Abstract Global Wallet.
chain
Chain
required
The chain to deploy the contract on. e.g. abstractTestnet.
args
Inferred from ABI
Constructor arguments to call upon deployment.
deploymentType
'create' | 'create2' | 'createAccount' | 'create2Account'
Specifies the type of contract deployment. Defaults to create.
factoryDeps
Hex[]
An array of bytecodes of contracts that are dependencies for the contract being deployed. This is used for deploying contracts that depend on other contracts that are not yet deployed on the network.Learn more on the Contract deployment page.
salt
Hash
Specifies a unique identifier for the contract deployment.
gasPerPubdata
bigint
The amount of gas to pay per byte of data on Ethereum.
paymaster
Account | Address
Address of the paymaster smart contract that will pay the gas fees of the deployment transaction.Must also provide a paymasterInput field.
paymasterInput
Hex
Input data to the paymaster.Must also provide a paymaster field.

Returns

Returns the Hex hash of the transaction that deployed the contract. Use waitForTransactionReceipt to get the transaction receipt from the hash.