Deploy Contract
Deploy a contract with bytecode and constructor arguments
Loading...
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 ( "github.com/ChefBingbong/viem-go/actions/wallet")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)},})Accountany — []byte, string, or *abi.ABIstring0x).[]anynil*chain.Chain — override for chain ID.*bool — default true; assert chain ID matches.*big.Intnilstring(SendTransactionReturnType, error) — the transaction hash (hex string).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.