DataLayer RPC
Note about Windows command escaping
This document will use Linux/MacOS RPC syntax. When running rpc commands on Windows, you'll need to escape all quotes with backslashes.
For example, here is a typical RPC command on Linux and MacOS:
chia rpc data_layer create_data_store '{"fee":"1000"}'
To run the same command on Windows, you need to escape the quotes with backslashes. In other words, add a \ before each double quote, such that:
"fee"
becomes\"fee\"
"1000"
becomes\"1000\"
- etc
Intro
This page includes a comprehensive list of Chia's DataLayer RPC API.
We also have documented the DataLayer CLI commands for interacting with the DataLayer.
By default, the DataLayer RPC API is exposed on port 8562. This is configured in ~/.chia/mainnet/config/config.yaml
under data_layer:rpc_port
. This port must not be exposed publicly for security concerns.
Commands that modify the blockchain include an optional fee. This fee can be specified in two ways:
- The "fee" parameter can be configured explicitly in the command, as several of the examples in this document show
- If the fee option is not explicitly specified, then the
data_layer:fee
setting in~/.chia/mainnet/config/config.yaml
will be used. By default, this is set to 1 billion mojos (0.001 XCH) - If neither of these options is set, then no fee will be used
For commands that change the state of the DataLayer singleton (ie all on-chain commands), you will need to wait for confirmation before running another command. If you run a command before the previous transaction has been confirmed, you will receive this error: Request failed: {'error': 'Already have a pending root waiting for confirmation.', 'success': False}
Note: Hashes used as arguments for the commands documented here may or may not be prefixed with 0x
. Both forms are valid syntax.
Reference
add_mirror
Functionality: Add a new mirror from an owned or subscribed data store. Triggers a Chia transaction
Usage: chia rpc data_layer [OPTIONS] add_mirror [REQUEST]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-j | --json-file | FILENAME | False | Optionally instead of REQUEST you can provide a json file containing the request data |
-h | --help | None | False | Show a help message and exit |
Request Parameters:
Flag | Type | Required | Description |
---|---|---|---|
id | TEXT | True | The hexadecimal ID of the store to mirror |
urls | TEXT | True | A list of URLs where the mirror will reside |
amount | INTEGER | True | The number of mojos to spend to create the mirror. In theory, mirrors with a higher amount will be prioritized |
fee | TEXT | False | Set the fee for the transaction, in mojos |
Example
Create one mirror with multiple URLs:
chia rpc data_layer add_mirror '{"id":"0x1ad0908e248f48cc3e9b3cf8f68c748d2e3c5a2a933765032d3222086231ea5e", "urls":["http://www.example.com:8575", "http://www.example2.com:8575"], "amount":1000000}'
Response:
{
"success": true
}
add_missing_files
Functionality: Use the database to restore all files for one or more owned data stores
Note: For subscribed stores, this command will do nothing. Use unsubscribe and subscribe instead
Usage: chia rpc data_layer [OPTIONS] add_missing_files [REQUEST]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-j | --json-file | FILENAME | False | Optionally instead of REQUEST you can provide a json file containing the request data |
-h | --help | None | False | Show a help message and exit |
Request Parameters:
Flag | Type | Required | Description |
---|---|---|---|
ids | TEXT | False | A list of hexadecimal store IDs to restore (default: all subscribed stores) |
override | BOOLEAN | False | If True , will overwrite files that already exist (default: False ) |
foldername | TEXT | False | The name of the folder where the files to be restored are located (default: ~/.chia/mainnet/data_layer/db/server_files_location_<network> ) |
Example
For this example, there is one owned store:
ls ~/.chia/mainnet/data_layer/db/server_files_location_testnet10/
Response:
1ad0908e248f48cc3e9b3cf8f68c748d2e3c5a2a933765032d3222086231ea5e-b5420e65846ded936d1e4855c066247fc461a3b281cd9e0e69f3cfa4df529ba2-delta-1-v1.0.dat
1ad0908e248f48cc3e9b3cf8f68c748d2e3c5a2a933765032d3222086231ea5e-b5420e65846ded936d1e4855c066247fc461a3b281cd9e0e69f3cfa4df529ba2-full-1-v1.0.dat
Intentionally move the files and create an empty folder. This will simulate file corruption:
mv ~/.chia/mainnet/data_layer/db/server_files_location_testnet10 ~/.chia/mainnet/data_layer/db/server_files_location_testnet10_bak
mkdir ~/.chia/mainnet/data_layer/db/server_files_location_testnet10/
Next, restore the files:
chia rpc data_layer add_missing_files
Response:
{
"success": true
}
Finally, verify that the files have been restored:
ls ~/.chia/mainnet/data_layer/db/server_files_location_testnet10/
Response:
1ad0908e248f48cc3e9b3cf8f68c748d2e3c5a2a933765032d3222086231ea5e-b5420e65846ded936d1e4855c066247fc461a3b281cd9e0e69f3cfa4df529ba2-delta-1-v1.0.dat
1ad0908e248f48cc3e9b3cf8f68c748d2e3c5a2a933765032d3222086231ea5e-b5420e65846ded936d1e4855c066247fc461a3b281cd9e0e69f3cfa4df529ba2-full-1-v1.0.dat
batch_update
Functionality: Apply multiple updates to a data store with a given changelist. Triggers a Chia transaction
Usage: chia rpc data_layer [OPTIONS] batch_update [REQUEST]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-j | --json-file | FILENAME | False | Optionally instead of REQUEST you can provide a json file containing the request data |
-h | --help | None | False | Show a help message and exit |
Request Parameters:
Flag | Type | Required | Description |
---|---|---|---|
id | TEXT | True | The hexadecimal store ID |
changelist | TEXT | True | A string representing the changelist |
submit_on_chain | BOOLEAN | False | Specify whether to submit the update to the blockchain (True ), or to store it locally (False ). Default: True (See info box for details) |
fee | TEXT | False | Set the fee for the transaction, in mojos |
The submit_on_chain
flag was added in Chia version 2.3.0. In order to support the new functionality (submit an update off-chain), the schema for your root
table will be upgraded automatically upon starting the DataLayer service. This upgrade takes about three minutes to complete.
A few notes on the changelist
option:
- The entire list must be formatted as a JSON array
- There are two actions allowed:
insert
anddelete
insert
requireskey
andvalue
flagsdelete
requires akey
flag only- Keys and values must be written in hex format. Values can be derived from text or binary.
- Labels, keys and values must all be enclosed in double quotes
- Multiple inserts and deletes are allowed
- The size of a single
value
flag is limited to 100 MiB. However, adding anything close to that size has not been tested and could produce unexpected results
The following examples will show the basic functionality of this command.
Example 1 -- Insert a single key/value pair
chia rpc data_layer batch_update '{"id":"0x1163ac212bd5fe00efa86f8d3c4958cda08924870800d72dc332f508a1b2e35a", "changelist":[{"action":"insert", "key":"0003", "value":"abc123"}]}'
Response:
{
"success": true,
"tx_id": "0x02c38815520bf517793418368c1a54641bc71318cad41b35932d0ceb7a489c5a"
}
Example 2 -- Delete a single key
chia rpc data_layer batch_update '{"id":"0x1163ac212bd5fe00efa86f8d3c4958cda08924870800d72dc332f508a1b2e35a", "changelist":[{"action":"delete", "key":"0003"}]}'
Response:
{
"success": true,
"tx_id": "0xddd4474cb1c17b4692a6600e54de52b8f0c982bb5321868b0a8071af571f131e"
}
Example 3 -- Insert two keys
chia rpc data_layer batch_update '{"id":"0x1163ac212bd5fe00efa86f8d3c4958cda08924870800d72dc332f508a1b2e35a", "changelist":[{"action":"insert", "key":"0x0004", "value":"123abc"},{"action":"insert", "key":"0005", "value":"0xbeadfeed"}]}'
Response:
{
"success": true,
"tx_id": "0x08403438a85afd1e3879f372f4d1b2987f3b677c20da1d61f840efd1fa5e3b74"
}
List all keys and values after running the previous command:
chia rpc data_layer get_keys_values '{"id":"0x1163ac212bd5fe00efa86f8d3c4958cda08924870800d72dc332f508a1b2e35a"}'
Response:
{
"keys_values": [
{
"atom": null,
"hash": "0x7e193b814080e50aa7780bcf71fd0422a0397ad3e57dc1eac71d93183efb39ba",
"key": "0x0004",
"value": "0x123abc"
},
{
"atom": null,
"hash": "0xc2dc94c2a85d7db4cfdd1d907bcc441c8fce595db2e2075b973fb8171e2f19a2",
"key": "0x0005",
"value": "0xbeadfeed"
}
],
"success": true
}
Example 4 -- Show that you may not overwrite an existing key
chia rpc data_layer batch_update '{"id":"0x1163ac212bd5fe00efa86f8d3c4958cda08924870800d72dc332f508a1b2e35a", "changelist":[{"action":"insert", "key":"0002", "value":"0123456789abcdef"}]}'
Response:
Request failed: {'error': 'Key already present: 0002', 'success': False}
Example 5 -- Delete and add the same key in the same command
chia rpc data_layer batch_update '{"id":"0x1163ac212bd5fe00efa86f8d3c4958cda08924870800d72dc332f508a1b2e35a", "changelist":[{"action":"delete", "key":"0002"},{"action":"insert", "key":"0002", "value":"0123456789abcdef"}]}'
Response:
{
"success": true,
"tx_id": "0xc4fb487f6506129c17283c30f553c9a767298330636e8bd1f7ea2311e183ed1e"
}
Show that the key/value pair has actually been updated:
chia rpc data_layer get_value '{"id":"0x1163ac212bd5fe00efa86f8d3c4958cda08924870800d72dc332f508a1b2e35a", "key":"0002"}'
Response:
{
"success": true,
"value": "0123456789abcdef"
}
Example 6 -- Show a key/value pair that was inserted into the Climate Warehouse
[
{
"action": "insert",
"key": "70726f6a6563747c37353339656336392d636238652d343464362d383832332d653062313135303162643433",
"value": "7b2263757272656e745265676973747279223a2243756c7469766f222c2272656769737472794f664f726967696e223a2243756c7469766f222c226f726967696e50726f6a6563744964223a224d6163546573743135222c2270726f6772616d223a224d6163546573743135222c2270726f6a6563744964223a224d6163546573743135222c2270726f6a6563744e616d65223a224d6163546573743135222c2270726f6a6563744c696e6b223a224d6163546573743135222c2270726f6a656374446576656c6f706572223a224d6163546573743135222c22736563746f72223a22456e6572677920646973747269627574696f6e222c2270726f6a65637454797065223a224f7a6f6e65204465706c6574696e67205375627374616e636573222c22636f766572656442794e4443223a224f757473696465204e4443222c226e6463496e666f726d6174696f6e223a224d6163546573743135222c2270726f6a656374537461747573223a22436f6d706c65746564222c22756e69744d6574726963223a2274434f3265222c226d6574686f646f6c6f6779223a22426173656c696e65204d6574686f646f6c6f677920666f72206465636f6d706f736974696f6e206f66204e324f2066726f6d206578697374696e672061646970696320616369642070726f64756374696f6e20706c616e7473202d2d2d2056657273696f6e20332e30222c2270726f6a65637454616773223a224d6163546573743135222c2276616c69646174696f6e426f6479223a22436172626f6e20436865636b2028496e646961292050726976617465204c74642e222c2270726f6a65637453746174757344617465223a22323032302d30332d32385430303a30303a30302e3030305a222c2276616c69646174696f6e44617465223a22323032322d30332d30315430303a30303a30302e3030305a222c2277617265686f75736550726f6a6563744964223a2237353339656336392d636238652d343464362d383832332d653062313135303162643433222c2274696d65537461676564223a313634363639343630322c226f7267556964223a2230623039643861653437626665323731366263323532383231333463653661613931616333646364663933363335616338656436626362333031626234636238227d"
}
]
The hex from this example can be decoded to obtain the following:
key = project|7539ec69-cb8e-44d6-8823-e0b11501bd43
value = {
"currentRegistry":"Cultivo",
"registryOfOrigin":"Cultivo",
"originProjectId":"MacTest15",
"program":"MacTest15",
"projectId":"MacTest15",
"projectName":"MacTest15",
"projectLink":"MacTest15",
"projectDeveloper":"MacTest15",
"sector":"Energy distribution",
"projectType":"Ozone Depleting Substances",
"coveredByNDC":"Outside NDC",
"ndcInformation":"MacTest15",
"projectStatus":"Completed",
"unitMetric":"tCO2e",
"methodology":"Baseline Methodology for decomposition of N2O from existing adipic acid production plants --- Version 3.0",
"projectTags":"MacTest15",
"validationBody":"Carbon Check (India) Private Ltd.",
"projectStatusDate":"2020-03-28T00:00:00.000Z",
"validationDate":"2022-03-01T00:00:00.000Z",
"warehouseProjectId":"7539ec69-cb8e-44d6-8823-e0b11501bd43",
"timeStaged":1646694602,
"orgUid":"0b09d8ae47bfe2716bc25282134ce6aa91ac3dcdf93635ac8ed6bcb301bb4cb8"
}
cancel_offer
Functionality: Cancel a DataLayer offer
Usage: chia rpc data_layer [OPTIONS] cancel_offer [REQUEST]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-j | --json-file | FILENAME | False | Optionally instead of REQUEST you can provide a json file containing the request data |
-h | --help | None | False | Show a help message and exit |
Request Parameters:
Flag | Type | Required | Description |
---|---|---|---|
trade_id | TEXT | True | The trade_id of the offer. This is displayed with the response of the make_offer RPC |
secure | BOOLEAN | True | If true , the offer will be canceled on the blockchain, making it impossible to be accepted later. If false , the offer will only be canceled locally. We recommend that you set this to true unless you are certain that the offer file has not left your computer |
fee | TEXT | False | If secure is true , this will set the fee for the transaction, in mojos. If secure is false , the fee will be ignored |
Example
Cancel an offer on-chain, using "secure":"true":
chia rpc data_layer cancel_offer '{"trade_id":"92652561cc3f40677d7d73513b4dde4a56da1c9edc0cfd9f03bb001b95df42af", "secure":"true", "fee":"1000"}'
Response:
{
"success": true
}
check_plugins
Functionality: Get information about configured uploader/downloader plugins
Usage: chia rpc data_layer [OPTIONS] check_plugins [REQUEST]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-j | --json-file | FILENAME | False | Optionally instead of REQUEST you can provide a json file containing the request data |
-h | --help | None | False | Show a help message and exit |
Request Parameters: None
Example
chia rpc data_layer check_plugins
Response:
{
"plugin_status": {
"downloaders": {},
"uploaders": {}
},
"success": true
}
clear_pending_roots
Functionality: Clear pending roots that will not be published, associated data may not be recoverable
Usage: chia rpc data_layer [OPTIONS] clear_pending_roots [REQUEST]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-j | --json-file | FILENAME | False | Optionally instead of REQUEST you can provide a json file containing the request data |
-h | --help | None | False | Show a help message and exit |
Request Parameters:
Flag | Type | Required | Description |
---|---|---|---|
store_id | TEXT | True | The hexadecimal store ID |
Example
chia rpc data_layer clear_pending_roots '{"store_id":"2772c8108e19f9fa98ff7bc7d4bafd821319bc90af6b610d086b85f4c21fa816"}'
Response:
{
"root": {
"generation": 2,
"node_hash": "ab8da7d5adec29fe1d12888fec462d0b18d72cec975599e178f98037cf3b8d13",
"status": 1,
"tree_id": "2772c8108e19f9fa98ff7bc7d4bafd821319bc90af6b610d086b85f4c21fa816"
},
"success": true
}
create_data_store
Functionality: Create a data store. Triggers a Chia transaction
Usage: chia rpc data_layer [OPTIONS] create_data_store [REQUEST]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-j | --json-file | FILENAME | False | Optionally instead of REQUEST you can provide a json file containing the request data |
-h | --help | None | False | Show a help message and exit |
Request Parameters:
Flag | Type | Required | Description |
---|---|---|---|
fee | TEXT | False | Set the fee for the transaction, in mojos |
Example
chia rpc data_layer create_data_store '{"fee":"1000"}'
Response:
{
"id": "31264f736a07683097a4b1bbedfa3b4d12631af1595b3905907a441bafb79c61",
"success": true,
"txs": [
{
"additions": [
{
"amount": 1,
"parent_coin_info": "0x7a97a37cac145bd13b4da93c496dc32e83a526918727e0f6a1c305af996726e9",
"puzzle_hash": "0xeff07522495060c066f66f32acc2a77e3a3e737aca8baea4d1a64ea4cdc13da9"
},
{
"amount": 10983998895994,
"parent_coin_info": "0x7a97a37cac145bd13b4da93c496dc32e83a526918727e0f6a1c305af996726e9",
"puzzle_hash": "0xdc2d295cce761abd4123d03e7135c670d6c0ad39ec4e66503cec336439e8a2fb"
},
{
"amount": 1,
"parent_coin_info": "0x31264f736a07683097a4b1bbedfa3b4d12631af1595b3905907a441bafb79c61",
"puzzle_hash": "0xba017f832d945b23f7b0a3dc4850a3bb9aff6e92cd2a333a7987b60ced1dab0a"
}
],
"amount": 1,
"confirmed": false,
"confirmed_at_height": 0,
"created_at_time": 1660784389,
"fee_amount": 1000,
"memos": [],
"name": "0x76d1e179a15f097c116e75c73486c3d47f7ebbb4791b5216a2828807f4ad9a5f",
"removals": [
{
"amount": 10983998896995,
"parent_coin_info": "0x110a907b5676553746e75623dd32ad231c080e9dabe50a99bc43beebaaa13531",
"puzzle_hash": "0x3f5ea6f0f46c1d76fbc72e4116895536f7b7b167f9d9e5a38d708ad3e3fd434a"
},
{
"amount": 1,
"parent_coin_info": "0x7a97a37cac145bd13b4da93c496dc32e83a526918727e0f6a1c305af996726e9",
"puzzle_hash": "0xeff07522495060c066f66f32acc2a77e3a3e737aca8baea4d1a64ea4cdc13da9"
}
],
"sent": 10,
"sent_to": [],
"spend_bundle": {
"aggregated_signature": "0xb600c2cd9ddafb6655e14fe99b293a742746ba82ef3f05b8bb3a375af0d3824011a1909348a16745e19f826aceb2534e08c0d939f01eb92f9bfac5eb8cf0c97bad353d5e0fa89f95f329c45c5797d59fe4b1a8ce23fa6a64bd2ac385170fedd5",
"coin_spends": [
{
"coin": {
"amount": 10983998896995,
"parent_coin_info": "0x110a907b5676553746e75623dd32ad231c080e9dabe50a99bc43beebaaa13531",
"puzzle_hash": "0x3f5ea6f0f46c1d76fbc72e4116895536f7b7b167f9d9e5a38d708ad3e3fd434a"
},
"puzzle_reveal": "0xff02ffff01ff02ffff01ff02ffff03ff0bffff01ff02ffff03ffff09ff05ffff1dff0bffff1effff0bff0bffff02ff06ffff04ff02ffff04ff17ff8080808080808080ffff01ff02ff17ff2f80ffff01ff088080ff0180ffff01ff04ffff04ff04ffff04ff05ffff04ffff02ff06ffff04ff02ffff04ff17ff80808080ff80808080ffff02ff17ff2f808080ff0180ffff04ffff01ff32ff02ffff03ffff07ff0580ffff01ff0bffff0102ffff02ff06ffff04ff02ffff04ff09ff80808080ffff02ff06ffff04ff02ffff04ff0dff8080808080ffff01ff0bffff0101ff058080ff0180ff018080ffff04ffff01b0a50a6518ead71676147c2ee69111eaf7ad247fc624f4ae8e7c2a7fdfd28c8a31560183506bfa9c657af220e0caacc378ff018080",
"solution": "0xff80ffff01ffff33ffa0eff07522495060c066f66f32acc2a77e3a3e737aca8baea4d1a64ea4cdc13da9ff0180ffff33ffa0dc2d295cce761abd4123d03e7135c670d6c0ad39ec4e66503cec336439e8a2fbff8609fd695a377a80ffff34ff8203e880ffff3cffa0b7fe85c45d675c4798e49b89c334dc345acdecb7955467e849c367b47495700e80ffff3dffa0cb7418c46c146ecf8515b5ec562c8d6884c6ff5a28daecfdb4a37301b3b92bb38080ff8080"
},
{
"coin": {
"amount": 1,
"parent_coin_info": "0x7a97a37cac145bd13b4da93c496dc32e83a526918727e0f6a1c305af996726e9",
"puzzle_hash": "0xeff07522495060c066f66f32acc2a77e3a3e737aca8baea4d1a64ea4cdc13da9"
},
"puzzle_reveal": "0xff02ffff01ff04ffff04ff04ffff04ff05ffff04ff0bff80808080ffff04ffff04ff0affff04ffff02ff0effff04ff02ffff04ffff04ff05ffff04ff0bffff04ff17ff80808080ff80808080ff808080ff808080ffff04ffff01ff33ff3cff02ffff03ffff07ff0580ffff01ff0bffff0102ffff02ff0effff04ff02ffff04ff09ff80808080ffff02ff0effff04ff02ffff04ff0dff8080808080ffff01ff0bffff0101ff058080ff0180ff018080",
"solution": "0xffa0ba017f832d945b23f7b0a3dc4850a3bb9aff6e92cd2a333a7987b60ced1dab0aff01ffffa00000000000000000000000000000000000000000000000000000000000000000ffa0a5927d1773b24c508abb547f7fb803c57841dc2ef85c3074707355830ddb1f7e8080"
}
]
},
"to_puzzle_hash": "0x0202020202020202020202020202020202020202020202020202020202020202",
"trade_id": null,
"type": 0,
"wallet_id": 0
},
{
"additions": [
{
"amount": 1,
"parent_coin_info": "0x7a97a37cac145bd13b4da93c496dc32e83a526918727e0f6a1c305af996726e9",
"puzzle_hash": "0xeff07522495060c066f66f32acc2a77e3a3e737aca8baea4d1a64ea4cdc13da9"
},
{
"amount": 10983998895994,
"parent_coin_info": "0x7a97a37cac145bd13b4da93c496dc32e83a526918727e0f6a1c305af996726e9",
"puzzle_hash": "0xdc2d295cce761abd4123d03e7135c670d6c0ad39ec4e66503cec336439e8a2fb"
}
],
"amount": 1,
"confirmed": false,
"confirmed_at_height": 0,
"created_at_time": 1660784389,
"fee_amount": 1000,
"memos": [],
"name": "0xa3128e387ecc892f9b4d7e0178ee3fab5620659b0dabcf34dd3305e0e10d221d",
"removals": [
{
"amount": 10983998896995,
"parent_coin_info": "0x110a907b5676553746e75623dd32ad231c080e9dabe50a99bc43beebaaa13531",
"puzzle_hash": "0x3f5ea6f0f46c1d76fbc72e4116895536f7b7b167f9d9e5a38d708ad3e3fd434a"
}
],
"sent": 0,
"sent_to": [],
"spend_bundle": null,
"to_puzzle_hash": "0xeff07522495060c066f66f32acc2a77e3a3e737aca8baea4d1a64ea4cdc13da9",
"trade_id": null,
"type": 1,
"wallet_id": 1
}
]
}
As a result of running the create_data_store
command, a new DataLayer wallet is created:
chia wallet show
Response:
Wallet height: 1399892
Sync status: Synced
Balances, fingerprint: 1871575185
Chia Wallet:
-Total Balance: 10.983998895994 txch (10983998895994 mojo)
-Pending Total Balance: 10.983998895994 txch (10983998895994 mojo)
-Spendable: 10.983998895994 txch (10983998895994 mojo)
-Type: STANDARD_WALLET
-Wallet ID: 1
DataLayer Wallet:
-Total Balance: 0.0
-Pending Total Balance: 0.0
-Spendable: 0.0
-Type: DATA_LAYER
-Wallet ID: 2
delete_key
Functionality: Delete a key/value pair from a store that you control. Triggers a Chia transaction
Usage: chia rpc data_layer [OPTIONS] delete_key [REQUEST]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-j | --json-file | FILENAME | False | Optionally instead of REQUEST you can provide a json file containing the request data |
-h | --help | None | False | Show a help message and exit |
Request Parameters:
Flag | Type | Required | Description |
---|---|---|---|
id | TEXT | True | The hexadecimal store ID |
key | TEXT | True | The hexadecimal key |
fee | TEXT | False | Set the fee for the transaction, in mojos |
Example:
Example
chia rpc data_layer delete_key '{"id":"0x1163ac212bd5fe00efa86f8d3c4958cda08924870800d72dc332f508a1b2e35a", "key":"0001", "fee":"100000"}'
Response:
{
"success": true,
"tx_id": "0x6cfbaff3f739f4b0e1d0fae3475966f0d4a19b8a89b483af1bf1cdc789bb9f3c"
}
delete_mirror
Functionality: Delete a mirror, by coin_id
. Triggers a Chia transaction
Usage: chia rpc data_layer [OPTIONS] delete_mirror [REQUEST]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-j | --json-file | FILENAME | False | Optionally instead of REQUEST you can provide a json file containing the request data |
-h | --help | None | False | Show a help message and exit |
Request Parameters:
Flag | Type | Required | Description |
---|---|---|---|
id | TEXT | True | The coin_id of the mirror to delete, obtainable by running get_mirrors |
fee | TEXT | False | Set the fee for the transaction, in mojos |
Example 1
chia rpc data_layer delete_mirror '{"id":"0x9a2132858b81907875a65123e592b7aea80b23724202ac21bba0aedf583f7427"}'
Response:
{
"success": true
}
Example 2
If you attempt to delete a mirror you did not create, this will fail:
chia rpc data_layer delete_mirror '{"id":"0x83a75913f8222eebfbc047d2ab3bf4b92bd5c37f3acaa336a0bb8b3b3168c879"}'
Response:
Request failed: {'error': "{'error': 'DL Wallet does not have permission to delete mirror with ID 83a75913f8222eebfbc047d2ab3bf4b92bd5c37f3acaa336a0bb8b3b3168c879', 'success': False}", 'success': False}
get_ancestors
Functionality: Return all ancestors of a given hash
Usage: chia rpc data_layer [OPTIONS] get_ancestors [REQUEST]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-j | --json-file | FILENAME | False | Optionally instead of REQUEST you can provide a json file containing the request data |
-h | --help | None | False | Show a help message and exit |
Request Parameters:
Flag | Type | Required | Description |
---|---|---|---|
id | TEXT | True | The hexadecimal store ID |
hash | TEXT | True | The hash from which to display ancestors |
Example
First get the root hash of a data store:
chia rpc data_layer get_root '{"id":"0x1ad0908e248f48cc3e9b3cf8f68c748d2e3c5a2a933765032d3222086231ea5e"}'
Response:
{
"confirmed": true,
"hash": "0xb5420e65846ded936d1e4855c066247fc461a3b281cd9e0e69f3cfa4df529ba2",
"success": true,
"timestamp": 1660724174
}
Next, get the ancestors of the root hash:
chia rpc data_layer get_ancestors '{"id":"0x1ad0908e248f48cc3e9b3cf8f68c748d2e3c5a2a933765032d3222086231ea5e","hash":"0xb5420e65846ded936d1e4855c066247fc461a3b281cd9e0e69f3cfa4df529ba2"}'
Response:
{
"ancestors": [],
"success": true
}
get_keys
Functionality: Get all keys associated with a store_id
Usage: chia rpc data_layer [OPTIONS] get_keys [REQUEST]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-j | --json-file | FILENAME | False | Optionally instead of REQUEST you can provide a json file containing the request data |
-h | --help | None | False | Show a help message and exit |
Request Parameters:
Flag | Type | Required | Description |
---|---|---|---|
id | TEXT | True | The hexadecimal store ID |
root_hash | TEXT | False | The root hash from which to obtain data |
page | NUMBER | False | Enables pagination of the output and requests a specific page |
max_page_size | NUMBER | False | Set how many bytes to be included in a page. Only used if pagination is enabled. Default is 40 MB |
The root_hash
parameter is recommended to be used each time you call this RPC. If root_hash
is not specified, there is no way to guarantee that the latest data is being shown (stale data may be shown instead). This parameter is obtainable by calling the get_root RPC.
Pagination is disabled by default. If it is enabled (by using the page
flag), then the JSON response will include total_pages
and total_bytes
, in addition to the data.
If an item is larger than max_page_size
, an error will be thrown.
Example
chia rpc data_layer get_keys '{"id":"0x8f9601eba73a276d5b9e12fbec52b113217e89a55831ae1d80bca48462fbaea7", "root_hash": "0x9527cc5e43bf93062423221e9bec761cbc3f24a0811cb0738da2419dfe7649f7"}'
Response:
{
"keys": ["0x0001", "0x0002", "0x0003"],
"success": true
}
get_keys_values
Functionality: Get all keys and values for a store. Must be subscribed to store ID
Usage: chia rpc data_layer [OPTIONS] get_keys_values [REQUEST]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-j | --json-file | FILENAME | False | Optionally instead of REQUEST you can provide a json file containing the request data |
-h | --help | None | False | Show a help message and exit |
Request Parameters:
Flag | Type | Required | Description |
---|---|---|---|
id | TEXT | True | The hexadecimal store ID |
root_hash | TEXT | False | The root hash from which to obtain data |
page | NUMBER | False | Enables pagination of the output and requests a specific page |
max_page_size | NUMBER | False | Set how many bytes to be included in a page. Only used if pagination is enabled. Default is 40 MB |
The root_hash
parameter is recommended to be used each time you call this RPC. If root_hash
is not specified, there is no way to guarantee that the latest data is being shown (stale data may be shown instead). This parameter is obtainable by calling the get_root RPC.
Pagination is disabled by default. If it is enabled (by using the page
flag), then the JSON response will include total_pages
and total_bytes
, in addition to the data.
If an item is larger than max_page_size
, an error will be thrown.
Example
First, we'll show show an example that does not specify the root hash. This will result in stale data being displayed, per the above message.
Note: omitting the root_hash
is not recommended. Later, we will show the recommended way to call this RPC.
chia rpc data_layer get_keys_values '{"id":"0x8f9601eba73a276d5b9e12fbec52b113217e89a55831ae1d80bca48462fbaea7"}'
Response:
{
"keys_values": [
{
"atom": null,
"hash": "0xa03d7ea8e488d6443f51a8b586f11754447fb449dc48af881ee78ff77ec7cdb1",
"key": "0x0001",
"value": "0xfadedcab"
},
{
"atom": null,
"hash": "0x919735911d7f9ca0de316878ddb92e7772c9f39bf9d37e9d84ccab39f5d49a11",
"key": "0x0002",
"value": "0xcafef00d"
}
],
"success": true
}
Next, we will obtain the latest root_hash
value:
chia rpc data_layer get_root '{"id":"0x8f9601eba73a276d5b9e12fbec52b113217e89a55831ae1d80bca48462fbaea7"}'
Response:
{
"confirmed": true,
"hash": "0x9527cc5e43bf93062423221e9bec761cbc3f24a0811cb0738da2419dfe7649f7",
"success": true,
"timestamp": 1679023336
}
Finally, we will call the RPC again, this time with the latest root_hash
:
chia rpc data_layer get_keys_values '{"id":"0x8f9601eba73a276d5b9e12fbec52b113217e89a55831ae1d80bca48462fbaea7", "root_hash": "0x9527cc5e43bf93062423221e9bec761cbc3f24a0811cb0738da2419dfe7649f7"}'
The result now contains all of theys anf values from the id
:
{
"keys_values": [
{
"atom": null,
"hash": "0xa03d7ea8e488d6443f51a8b586f11754447fb449dc48af881ee78ff77ec7cdb1",
"key": "0x0001",
"value": "0xfadedcab"
},
{
"atom": null,
"hash": "0x919735911d7f9ca0de316878ddb92e7772c9f39bf9d37e9d84ccab39f5d49a11",
"key": "0x0002",
"value": "0xcafef00d"
},
{
"atom": null,
"hash": "0xe488fa1bf0f712b224df0daf312b3d479f80e3a330d4bebd8f26a0d52dc0ebbb",
"key": "0x0003",
"value": "0xabc123"
}
],
"success": true
}
get_kv_diff
Functionality: Get the kv diff between two hashes within the same store ID
Usage: chia rpc data_layer [OPTIONS] get_kv_diff [REQUEST]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-j | --json-file | FILENAME | False | Optionally instead of REQUEST you can provide a json file containing the request data |
-h | --help | None | False | Show a help message and exit |
Request Parameters:
Flag | Type | Required | Description |
---|---|---|---|
id | TEXT | True | The hexadecimal store ID |
hash_1 | TEXT | True | The first hash to compare |
hash_2 | TEXT | True | The second hash to compare |
page | NUMBER | False | Enables pagination of the output and requests a specific page |
max_page_size | NUMBER | False | Set how many bytes to be included in a page. Only used if pagination is enabled. Default is 40 MB |
Pagination is disabled by default. If it is enabled (by using the page
flag), then the JSON response will include total_pages
and total_bytes
, in addition to the data.
If an item is larger than max_page_size
, an error will be thrown.
Example
chia rpc data_layer get_kv_diff '{"id":"0x1163ac212bd5fe00efa86f8d3c4958cda08924870800d72dc332f508a1b2e35a", "hash_1":"0x7e193b814080e50aa7780bcf71fd0422a0397ad3e57dc1eac71d93183efb39ba", "hash_2":"0x2477500c19f0ddfb147049769ce54425a4c4e2994a25e63e51c389cb8f0e912f"}'
Response:
{
"diff": [
{
"key": "0004",
"type": "DELETE",
"value": "123abc"
},
{
"key": "0002",
"type": "INSERT",
"value": "0123456789abcdef"
}
],
"success": true
}
get_local_root
Functionality: Get the root hash and timestamp of a store ID. Can be used for either owned or subscribed stores
Usage: chia rpc data_layer [OPTIONS] get_local_root [REQUEST]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-j | --json-file | FILENAME | False | Optionally instead of REQUEST you can provide a json file containing the request data |
-h | --help | None | False | Show a help message and exit |
Request Parameters:s
Flag | Type | Required | Description |
---|---|---|---|
id | TEXT | True | The hexadecimal store ID |
Example
chia rpc data_layer get_local_root '{"id":"8f6ed792bbbf5216f8e55064793f74ce01286b9c1d542cc4a357cf7f8712df1d"}'
Response:
{
"hash": "0xcdb172490d2d1838e7cca24e28e2089ccbacf0e03b0f3d0a61eedae8462b3e75",
"success": true
}
get_mirrors
Functionality: List all mirrors for a store ID
Usage: chia rpc data_layer [OPTIONS] get_mirrors [REQUEST]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-j | --json-file | FILENAME | False | Optionally instead of REQUEST you can provide a json file containing the request data |
-h | --help | None | False | Show a help message and exit |
Request Parameters:
Flag | Type | Required | Description |
---|---|---|---|
id | TEXT | True | The hexadecimal ID of the store for which to list mirrors |
Example
chia rpc data_layer get_mirrors '{"id":"0x1ad0908e248f48cc3e9b3cf8f68c748d2e3c5a2a933765032d3222086231ea5e"}'
Response:
{
"mirrors": [
{
"amount": 1000000,
"coin_id": "11f450c2f706cda88b3373855b3780d36822a7f0e94297eb88de7c63eb0bd4c7",
"launcher_id": "1ad0908e248f48cc3e9b3cf8f68c748d2e3c5a2a933765032d3222086231ea5e",
"ours": true,
"urls": ["http://www.example.com:8575", "http://www.example2.com:8575"]
}
],
"success": true
}
get_owned_stores
Functionality: List the id (store_id
) of each data_store owned by this wallet
Usage: chia rpc data_layer [OPTIONS] get_owned_stores [REQUEST]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-j | --json-file | FILENAME | False | Optionally instead of REQUEST you can provide a json file containing the request data |
-h | --help | None | False | Show a help message and exit |
Request Parameters: None
Example
chia rpc data_layer get_owned_stores
Response:
{
"store_ids": [
"1163ac212bd5fe00efa86f8d3c4958cda08924870800d72dc332f508a1b2e35a"
],
"success": true
}
get_proof
Functionality: Obtains a merkle proof of inclusion for a given key
Usage: chia rpc data_layer [OPTIONS] get_proof [REQUEST]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-j | --json-file | FILENAME | False | Optionally instead of REQUEST you can provide a json file containing the request data |
-h | --help | None | False | Show a help message and exit |
Request Parameters:
Flag | Type | Required | Description |
---|---|---|---|
store_id | TEXT | True | The hexadecimal store ID |
keys | STRING LIST | True | A list of keys for which to retrieve proofs |
The proof is a proof of inclusion that a given key, value pair is in the specified datalayer store by chaining the Merkle hashes up to the published on-chain root hash.
A user can generate a proof for multiple k,v pairs in the same datastore.
Example
chia rpc data_layer get_proof '{"store_id": "7de232eecc08dc5e524ad42fad205c9ec7dd3f342677edb7c2e139c51f55d40e", "keys": ["0x0003"]}'
Response:
{
"proof": {
"coin_id": "0x774e5f9ba7a8afbfa7fd2050347b4a2d400d3cd530637a18b61b094bb5a0f756",
"inner_puzzle_hash": "0x875cc80014bc72f2028c27500d5b44bf6906cd13ad16d7b5f4a5da77a06c8c2f",
"store_proofs": {
"proofs": [
{
"key_clvm_hash": "0xa143e7ffd81147f136f921fef88760c46c7a05f15b81995f9c5cfed2a737a3f1",
"layers": [],
"node_hash": "0xe488fa1bf0f712b224df0daf312b3d479f80e3a330d4bebd8f26a0d52dc0ebbb",
"value_clvm_hash": "0xed052604ee4ff3996c15ef9b2cb0925233a2e78b6168bb6e67d133e074109b42"
}
],
"store_id": "0x7de232eecc08dc5e524ad42fad205c9ec7dd3f342677edb7c2e139c51f55d40e"
}
},
"success": true
}