Skip to main content

Issue a contract function request

You can use the API to interact with a collection contract by:

Each method uses a payload similar to:

Example payload
{
"arguments": ["1"]
}

The arguments property should contain all parameters in the correct order for the function.

note

To inspect a function and see which parameters it has, get the function details.

info

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
caution

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}
Example payload
{
"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
Example response
{
"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.