Construction-preprocess
Overview
This section details how to call the construction/preprocess
endpoint of the Rosetta construction API.
Preprocess is called prior to /construction/payloads
to construct a request for any metadata that is needed for transaction construction. The ICP Rosetta implementation will return the required list of public keys that has to be provided by the user and in the metadata it returns the request type that is associated with the given set of operations.
The metadata returned from this endpoint will be sent to the /construction/metadata
endpoint UNMODIFIED by the caller (in an offline execution environment).
The request and response types can be found in the official documentation.
An example of a call to the preprocess endpoint would resemble the following:
curl --location '0.0.0.0:8081/construction/preprocess' --header 'Content-Type: application/json' --data '{
"network_identifier": {
"blockchain": "Internet Computer",
"network": "00000000000000020101"
},
"operations": [
{
"operation_identifier": {
"index": 0
},
"type": "TRANSACTION",
"account": {
"address": "8b84c3a3529d02a9decb5b1a27e7c8d886e17e07ea0a538269697ef09c2a27b4"
},
"amount": {
"value": "-10",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
},
{
"operation_identifier": {
"index": 1
},
"type": "TRANSACTION",
"account": {
"address": "7f622708b363917e3ba0ef8ac1cb0dfe241ef5ffca54f32c1480473ee3a12cad"
},
"amount": {
"value": "10",
"currency": {
"symbol": "ICP",
"decimals": 8
}
}
}
],
"metadata": null
}'
Here you are creating two operations, one for debiting the account that the tokens are sent from and a credit operation for the account where the tokens are sent to.
For this example, you are sending ICP to the arbitrary account 7f622708b363917e3ba0ef8ac1cb0dfe241ef5ffca54f32c1480473ee3a12cad
.
Here you are creating two operations, one for debiting the account that the tokens are sent from and a credit operation for the account where the tokens are sent to.
For this example, you are sending ICP to the arbitrary account 7f622708b363917e3ba0ef8ac1cb0dfe241ef5ffca54f32c1480473ee3a12cad
.
and the response would look something like this. It contains two fields. The options
object has to be forwarded to the construction/metadata
endpoint to fetch network specific data.
The required_public_keys
field indicates for which account-id
the construction/payloads
endpoint will need the full public key.
{"options":{"request_types":["TRANSACTION"]},"required_public_keys":[{"address":"8b84c3a3529d02a9decb5b1a27e7c8d886e17e07ea0a538269697ef09c2a27b4"}]}⏎
It contains two fields. The options
object has to be forwarded to the construction/metadata
endpoint to fetch network specific data.
The required_public_keys
field indicates for which account-id
the construction/payloads
endpoint will need the full public key.
The required public keys in this case is the public key that corresponds to the sending account. You can derive this public key from the provided private key. To validate that the accountidentifiers
matches up, you can call construction/derive
with the public key.