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 can be provided in various formats including hex contract ID, StrKey-encoded contract ID, or other address types that can be converted using Address::fromAnyId().
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
Can be any type that can be converted to an address. E.g. hex contract id, StrKey contract id, hex claimable balance id, StrKey claimable balance id, etc. Use Address::fromAnyId($contractId) to get the exact type.
$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 ID (can be hex or StrKey-encoded)
- $functionName : string
-
The name of the function to invoke
- $arguments : array<string|int, XdrSCVal>|null = null
-
Optional array of function arguments
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 ID
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
Return values
XdrHostFunction —The XDR host function