Stellar PHP SDK API Documentation

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
see
HostFunction

Base class for all host functions

see
CreateContractHostFunction

For contracts without constructor arguments

see
UploadContractWasmHostFunction

For uploading WASM code first

see
https://developers.stellar.org

Stellar developer docs

since
1.0.0

Table of Contents

Properties

$address  : Address
$constructorArgs  : array<string|int, XdrSCVal>
$salt  : string
$wasmId  : string

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

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
throws
Exception

If random bytes generation fails


        
On this page

Search results