Stellar PHP SDK API Documentation

InvokeContractHostFunction extends HostFunction
in package

Represents a Soroban smart contract invocation host function

This host function type is used to invoke functions on deployed Soroban smart contracts. It specifies the contract to call, the function name, and any arguments to pass to the function.

The contract ID is a contract strkey ("C...") or the contract hash as 64 hexadecimal characters.

Usage: // Invoke a contract function without arguments $hostFunction = new InvokeContractHostFunction( "CCFIFQ...", // Contract ID "transfer" // Function name );

// Invoke a contract function with arguments $hostFunction = new InvokeContractHostFunction( "CCFIFQ...", "transfer", [XdrSCVal::forAddress($fromAddr), XdrSCVal::forAddress($toAddr), XdrSCVal::forU64(1000)] );

Tags
see
HostFunction

Base class for all host functions

Address

For address conversion utilities

https://developers.stellar.org

Stellar developer docs

since
1.0.0

Table of Contents

Properties

$arguments  : array<string|int, XdrSCVal>|null
$contractId  : string
$functionName  : string

Methods

__construct()  : mixed
Constructs a new InvokeContractHostFunction
fromXdr()  : InvokeContractHostFunction
Creates an InvokeContractHostFunction from XDR format
getArguments()  : array<string|int, XdrSCVal>|null
Gets the function arguments
getContractId()  : string
Gets the contract ID
getFunctionName()  : string
Gets the function name
setArguments()  : void
Sets the function arguments
setContractId()  : void
Sets the contract ID
setFunctionName()  : void
Sets the function name
toXdr()  : XdrHostFunction
Converts the invoke contract host function to XDR format

Properties

$contractId

public string $contractId

the contract to invoke, as a "C..." strkey or as 64 hexadecimal characters; an instance from fromXdr() holds the strkey of the address its XDR names, of any kind

Methods

__construct()

Constructs a new InvokeContractHostFunction

public __construct(string $contractId, string $functionName[, array<string|int, XdrSCVal>|null $arguments = null ]) : mixed
Parameters
$contractId : string

The contract to invoke, as a "C..." strkey or 64 hexadecimal characters

$functionName : string

The name of the function to invoke

$arguments : array<string|int, XdrSCVal>|null = null

Optional array of function arguments

Tags
throws
InvalidArgumentException

If the contract ID is not a contract address

getArguments()

Gets the function arguments

public getArguments() : array<string|int, XdrSCVal>|null
Return values
array<string|int, XdrSCVal>|null —

The array of Soroban values, or null if no arguments

getFunctionName()

Gets the function name

public getFunctionName() : string
Return values
string —

The function name

setArguments()

Sets the function arguments

public setArguments(array<string|int, XdrSCVal>|null $arguments) : void
Parameters
$arguments : array<string|int, XdrSCVal>|null

The array of Soroban values, or null for no arguments

setContractId()

Sets the contract ID

public setContractId(string $contractId) : void
Parameters
$contractId : string

The contract to invoke, as a "C..." strkey or 64 hexadecimal characters

Tags
throws
InvalidArgumentException

If the contract ID is not a contract address

setFunctionName()

Sets the function name

public setFunctionName(string $functionName) : void
Parameters
$functionName : string

The function name

toXdr()

Converts the invoke contract host function to XDR format

public toXdr() : XdrHostFunction

Encodes the contract ID as the address kind it names, so an instance from fromXdr() re-encodes to the XDR it was decoded from.

Tags
throws
InvalidArgumentException

If the contract ID names no address

Return values
XdrHostFunction —

The XDR host function

On this page

Search results