Issue a contract function request
You can use the API to interact with a collection contract by:
- Calling a function to return an on-chain value.
- Submitting a transaction that executes a function on-chain.
Each method uses a payload similar to:
{
"arguments": ["1"]
}
The arguments
property should contain all parameters in the correct order for the function.
To inspect a function and see which parameters it has, get the function details.
The collection contract must have functions_enabled
set to True
for the endpoint to be accessible. You can set this by editing the collection.
Read a value from a contract function
Issue a POST
request to the /functions/{function_id}/call
endpoint to read a value from the on-chain smart contract state.
POST https://admin-api.phosphor.xyz/v1/collections/{collection_id}/functions/{function_id}/call
A function can only be called this way if the stateMutability
in the ABI is equal to view
.
The output of this request is a JSON
object containing the on-chain state.
Execute a contract function
Enable manual execution
By default, contract functions aren't configured to be manually executed. A function must be configured for manual execution before it can be the target of this endpoint. Issue a PATCH
to the /functions/{function_id}
endpoint and pass in "enabled": true
.
PATCH https://admin-api.phosphor.xyz/v1/collections/{collection_id}/functions/{function_id}
{
"enabled": true
}
Submit the transaction
Issue a POST
request to the /functions/{function_id}/execute
endpoint to submit a transaction that executes a contract function.
POST https://admin-api.phosphor.xyz/v1/collections/{collection_id}/functions/{function_id}/execute
{
"transaction_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
This means that there's a pending transaction waiting to be picked up and executed by the platform.