Data Anchoring
This page introduces how to anchor service chain data to Klaytn main chain with Anchor API.
Before Getting Started
The x-chain-id value for calling the API is 8217 (Cypress) or 1001 (Baobab).
Essential parameters for calling APIs are described in individual examples.
Values that a user needs to enter for calling APIs will be represented with one pair of braces ({}). A user must enter the following values.
Item | Description | Note |
chain-id | 8217 or 1001 | Cypress(Klaytn mainnet) or Baobab(Klaytn testnet |
access-key-id | Auth ID |
|
secret-access-key | Auth Password |
|
krn | (optional) ID of Account Pool | Unnecessary when using Default Account Pool |
A KAS API Authentication Key (API Auth Key) provides access to all KAS services and all the rights to a Klaytn account which was created by calling Wallet API via this API Auth Key. The rights here include accessing and transferring all the assets (KLAY, etc.) of or sending a transaction from a Klaytn account. If you shared your API Auth Key with any unauthorized personnel, your Klaytn account could be compromised and might cause unwanted transaction execution.
DO NOT share your API Auth Key (Secret AccessKey or Authorization) with any unauthorized personnel. DO PUT efforts necessary to keep your API Auth Key safe for the security of your KAS/Klaytn account.
Create Operator
KAS Console - Service - Anchor - Operator
Click the “Create” button on the KAS Console - Service - Anchor - Operator menu. Click the button to display the screen for creating operators as follows.
Configure Transaction Fee Payments for Data Anchoring Transaction
For creating an operator on the KAS Console, set the account that would pay the anchoring transaction fee for data to be sent by the operator.
Parameter | Description |
feepayer | User fee delegation payment account address. Used when paying data anchoring transaction fees using the fee-payer account. |
useOperator | Whether the operator or KAS will pay data anchoring transaction fee (the transaction fee will be charged to the user) |
useGlobalFeepayer | Whether the fee payer account provided by KAS first pays the bill (the transaction fee will be charged to the user later) |
Use
useGlobalFeepayer
to send the data anchoring transaction even if the KLAY balance is insufficient.An error will occur if all thee parameters are not set.
The data anchoring transaction fee will be delegated according to the following priorities if one or more parameters are entered.
To ensure smooth execution of the anchoring transaction, use useGlobalFeepayer
.
To use feepayer, first create a Fee Delegation Account Pool and Fee Delegation Account.
The fee-payer account address (address
) and KRN
value of the fee delegation Account Pool are required to use the feepayer
.
The fee payment priority will be as follows if several parameters are used together to send anchoring transactions.
Priority | Parameter | the transaction fee payer |
1 |
| User’s separate fee-payer account |
2 |
| Operator |
3 |
| KAS (transaction fee will be charged to the user later) |
The account with higher priority will pay the anchoring transaction fee first if all three parameters are used. If the operator struggles to pay the transaction fee because of insufficient feepayer
account balance, the operator that sends an anchoring transaction will directly pay the fee as it has the next priority.
Expected Results by Parameter Settings
useGlobalFeepayer | feepayer | useOperator | Priority |
false | X | false | Error |
true | X | false | KAS |
false | X | true | Operator |
true | X | true | Operator > KAS |
false | O | false | User fee payer |
false | O | true | User fee payer > Operator |
true | O | true | User fee payer > Operator > KAS |
true | O | false | User fee payer > KAS |
Create Operator
Once the parameters are set, create an operator. The operator must have a different name from other operators on the current KAS account.
Operator You can check the created operator in the operator list. Or you can call all operator list search APIs and search.
For inquires about this document or KAS, please visit KAS Developer forum.
Get Operator List
API Request
Search for the list of created operators and setting values of each one. You may use the REST API or KAS SDKs (caver-js, caver-java extensions) for this.
Query Parameter
You can receive API response values with Cursor-based Pagination. The search range can also be set by second.
Parameter | Description | Example | Required or Not |
size | the number of items in the API response (min=1, max=1000, default=100) |
| False |
cursor | the cursor required to get the next batch of response items |
| False |
to-timestamp | Search Range: The last timestamp (sec) |
| False |
from-timestamp | Search Range: The first timestamp (sec) |
| False |
x-chain-id
is the id of the chain to which the operator was registered.
API Response
Here is the response of the Operator List Search API.
For details about this API, please visit here. For inquires about this document or KAS, please visit KAS Developer forum.
Get Operator Information
Or you can search for the created operator information with the operator’s Klaytn account address (operator-id).
API Request
Search for the settings and account balance of the operator above. You may use the REST API or KAS SDKs (caver-js, caver-java extensions) for this.
x-chain-id
is the id of the chain to which the operator was registered.
API Response
The response example of this API is as follows.
For details about this API, please visit here. For inquires about this document or KAS, please visit KAS Developer forum.
Send Data Anchoring Transaction
A user must call the Data Anchoring API to anchor the service chain data to the main chain. Request for the data anchoring transaction with the Klaytn account address of the operator created above.
Payload
The “payload” is the “data itself to anchor to the main chain.” Here are examples of “custom_field1” and “custom_field2” entered in the following payload value. Enter the required data to anchor to the main chain in JSON format (key:value), similar to “custom_field1” and “custom_field2,” to use the payload.
Enter the string in the “id” field to Search Anchoring Transaction using the string.
API Request
Call the Data Anchoring API as follows. You may use the REST API or KAS SDKs (caver-js, caver-java extensions) for this.
For details about data anchoring, please visit here.
If you want to use fee-delegation for sending this transaction, go to KAS Console - Anchor - Operator menu and configure fee-delegation. If you want to guarantee sending the anchoring transaction, please set UseGlobalFeePayer and use Anchor API.
API Response
A notification on whether the data anchoring is successful is returned as an API response.
For details about this API, please visit here. For inquires about this document or KAS, please visit KAS Developer forum. ㅏ
Get List of Anchoring Transaction by Operator Address
Search for the list of data anchoring transactions sent by this operator with the operator’s Klaytn account address.
API Request
Call the Anchoring Transaction Search API. You may use the REST API or KAS SDKs (caver-js, caver-java extensions) for this.
Query Parameter
You can receive API response values with Cursor-based Pagination. The search range can also be set by second.
Parameter | Description | Example | Required or Not |
size | the number of items in the API response (min=1, max=1000, default=100) |
| False |
cursor | the cursor required to get the next batch of response items |
| False |
to-timestamp | Search Range: The last timestamp (sec) |
| False |
from-timestamp | Search Range: The first timestamp (sec) |
| False |
API Response
Here is the response of the Anchoring Data Search API.
For details about this API, please visit here. For inquires about this document or KAS, please visit KAS Developer forum. ㅏ
Get Anchoring Transaction Information By Transaction Hash and Operator Address
You can use the transaction hash and operator address to search for payload details of anchoring transactions.
API Request
Call the Anchoring Transaction Details Search API. You may use the REST API or KAS SDKs (caver-js, caver-java extensions) for this.
API Response
Here is the response of the Anchoring Transaction Payload Details Search API.
For details about this API, please visit here. For inquires about this document or KAS, please visit KAS Developer forum.
Get Payload by Operator Address and Payload ID
You can use the payload ID and operator address to search for the payload details of anchoring transactions.
API Request
Call the Anchoring Transaction Details Search API. You may use the REST API or KAS SDKs (caver-js, caver-java extensions) for this.
API Response
Here is the response of the Anchoring Transaction Payload Details Search API.
For details about this API, please visit here. For inquires about this document or KAS, please visit KAS Developer forum.
Last updated