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
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
$arguments
public
array<string|int, XdrSCVal>|null
$arguments
Optional array of Soroban values to pass as function arguments
$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
$functionName
public
string
$functionName
The name of the contract function to invoke
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
fromXdr()
Creates an InvokeContractHostFunction from XDR format
public
static fromXdr(XdrHostFunction $xdr) : InvokeContractHostFunction
Parameters
- $xdr : XdrHostFunction
-
The XDR host function
Tags
Return values
InvokeContractHostFunction —The decoded host function
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
getContractId()
Gets the contract ID
public
getContractId() : string
Return values
string —The contract ID
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
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
Return values
XdrHostFunction —The XDR host function