CreateContractWithConstructorHostFunction
extends HostFunction
in package
Represents a Soroban host function for creating contracts with constructor arguments
This host function deploys a new smart contract instance from previously uploaded WASM code, similar to CreateContractHostFunction, but with support for passing constructor arguments. Constructor arguments are passed to the contract's initialization function during deployment.
This is useful for contracts that require initialization parameters, such as:
- Token contracts needing initial supply or admin addresses
- Contracts with configurable parameters
- Contracts requiring setup data at deployment time
Usage:
// Deploy contract with constructor arguments
$args = [
XdrSCVal::forSymbol("admin"),
XdrSCVal::forAddress($adminAddress),
XdrSCVal::forU64(1000000)
];
$hostFunction = new CreateContractWithConstructorHostFunction( Address::fromAccountId("GABC..."), // Deployer address $wasmId, // WASM hash from upload $args, // Constructor arguments $salt // Optional salt );
Tags
Table of Contents
Properties
Methods
- __construct() : mixed
- Constructs a new CreateContractWithConstructorHostFunction
- fromXdr() : HostFunction
- Creates a HostFunction from XDR format
- getAddress() : Address
- getConstructorArgs() : array<string|int, mixed>
- getSalt() : string
- getWasmId() : string
- setAddress() : void
- setConstructorArgs() : void
- setSalt() : void
- setWasmId() : void
- toXdr() : XdrHostFunction
- Converts the host function to XDR format
Properties
$address
public
Address
$address
The deployer address
$constructorArgs
public
array<string|int, XdrSCVal>
$constructorArgs
The constructor arguments
$salt
public
string
$salt
The salt value for contract address generation
$wasmId
public
string
$wasmId
The WASM ID (hash of the uploaded contract code)
Methods
__construct()
Constructs a new CreateContractWithConstructorHostFunction
public
__construct(Address $address, string $wasmId, array<string|int, XdrSCVal> $constructorArgs[, string|null $salt = null ]) : mixed
Parameters
- $address : Address
-
The deployer address
- $wasmId : string
-
The WASM ID (hash of uploaded contract code)
- $constructorArgs : array<string|int, XdrSCVal>
-
The constructor arguments
- $salt : string|null = null
-
Optional salt (32 random bytes generated if not provided)
Tags
fromXdr()
Creates a HostFunction from XDR format
public
static fromXdr(XdrHostFunction $xdr) : HostFunction
Parameters
- $xdr : XdrHostFunction
-
The XDR host function
Tags
Return values
HostFunction —The decoded host function instance
getAddress()
public
getAddress() : Address
Return values
AddressgetConstructorArgs()
public
getConstructorArgs() : array<string|int, mixed>
Return values
array<string|int, mixed>getSalt()
public
getSalt() : string
Return values
stringgetWasmId()
public
getWasmId() : string
Return values
stringsetAddress()
public
setAddress(Address $address) : void
Parameters
- $address : Address
setConstructorArgs()
public
setConstructorArgs(array<string|int, mixed> $constructorArgs) : void
Parameters
- $constructorArgs : array<string|int, mixed>
setSalt()
public
setSalt(string $salt) : void
Parameters
- $salt : string
setWasmId()
public
setWasmId(string $wasmId) : void
Parameters
- $wasmId : string
toXdr()
Converts the host function to XDR format
public
toXdr() : XdrHostFunction
Return values
XdrHostFunction —The XDR representation