Deploy Contract
Deploy a contract with bytecode and constructor arguments
DeployContract sends a transaction with no to address and data set to bytecode + ABI-encoded constructor arguments. Equivalent to viem’s deployContract. Requires a Wallet Client with an account.
Import
import ("github.com/ChefBingbong/viem-go/actions/wallet")
Usage
hash, err := wallet.DeployContract(ctx, walletClient, wallet.DeployContractParameters{ABI: contractABI,Bytecode: "0x608060405260405161083e38038061083e833981016040819052610...",})if err != nil {log.Fatal(err)}fmt.Println("Deployed tx:", hash)// With constructor argshash, err = wallet.DeployContract(ctx, walletClient, wallet.DeployContractParameters{ABI: contractABI,Bytecode: "0x6080604052...",Args: []any{"MyToken", "MTK", uint8(18)},})
Parameters
Account (optional)
- Type:
Account - Default: client’s default account
- Account to deploy from (must be set on client if omitted).
ABI (required)
- Type:
any—[]byte,string, or*abi.ABI - Contract ABI (used to encode constructor args).
Bytecode (required)
- Type:
string - Contract bytecode as hex string (with or without
0x).
Args (optional)
- Type:
[]any - Default:
nil - Constructor arguments in order. Omit for no-arg constructor.
Chain / AssertChainID (optional)
- Chain:
*chain.Chain— override for chain ID. - AssertChainID:
*bool— default true; assert chain ID matches.
Value (optional)
- Type:
*big.Int - Default:
nil - ETH to send with the deployment (e.g. for contracts that require payment).
DataSuffix (optional)
- Type:
string - Data to append after the deploy payload.
Gas, GasPrice, MaxFeePerGas, MaxPriorityFeePerGas, Nonce, Type (optional)
- Same as for other wallet transactions. Omit for defaults/estimation.
Return type
- DeployContract returns
(SendTransactionReturnType, error)— the transaction hash (hex string).
Encode deploy data
Deploy data is bytecode + abi.EncodeConstructor(args...). To build deploy data without sending, use a parsed ABI: concatenate bytecode bytes and parsedABI.EncodeConstructor(args...). See ABI Encoding for EncodeConstructor.
See also
- Writing Contracts — WriteContract
- Estimate Contract Gas — estimate deployment gas
- ABI Encoding — EncodeConstructor