DataLayer CLI
This page includes a comprehensive list of Chia's Command Line Interface commands for interacting with the DataLayer.
We also have documented the RPC API for interacting with the DataLayer.
The relevant DataLayer commands can be found by running chia data
:
(venv) $ chia data -h
Commands that modify the blockchain include an optional fee. This fee can be specified in two ways:
- The
-m
/--fee
parameter can be specified 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}
The commands in this document will work with or without the =
symbol. Additionally, hashes may or may not be prefixed with 0x
.
Reference
add_mirror
Functionality: Add a new mirror from a local or remote data store. Triggers a Chia transaction
Usage: chia data add_mirror [OPTIONS]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-i | --id | TEXT | True | The hexadecimal ID of the store to mirror |
-a | --amount | INTEGER | True | The amount (in mojos) to spend to create the mirror. In theory, mirrors with a higher amount will be prioritized. Minimum amount is 0 |
-u | --url | TEXT | False | A URL where the mirror will reside. Can be repeated to add multiple URLs in the same command |
-m | --fee | TEXT | False | Set the fees for the transaction, in XCH |
-dp | --data-rpc-port | INTEGER | False | Set the port where the DataLayer is hosting the RPC interface. See rpc_port under wallet in config.yaml |
-f | --fingerprint | INTEGER | False | Fingerprint of the wallet to use |
-h | --help | None | False | Show a help message and exit |
Example
Create one mirror with multiple URLs:
chia data add_mirror -i 1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f -a 1000 -u http://www.example.com:8575 -u http://www.example2.com:8575
Response:
None
add_missing_files
Functionality: Use the database to restore all files for one or more local data stores
Usage: chia data add_missing_files [OPTIONS]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-i | --ids | TEXT | True | The hexadecimal store id(s) |
-o | --override | None | False | If set, will overwrite files that already exist (default: not set) |
-n | --no-override | None | False | If set, will not overwrite files that already exist (default: set) |
-d | --directory | TEXT | False | If specified, use a non-default directory to write the files (default: ~/.chia/mainnet/data_layer/db/server_files_location_<network> ) |
-dp | --data-rpc-port | INTEGER | False | Set the port where the DataLayer is hosting the RPC interface. See rpc_port under data_layer in config.yaml |
-f | --fingerprint | INTEGER | False | Fingerprint of the wallet to use |
-h | --help | None | False | Show a help message and exit |
Example
For this example, there is one local store:
ls ~/.chia/mainnet/data_layer/db/server_files_location_testnet/
Response:
1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f-0000000000000000000000000000000000000000000000000000000000000000-delta-2-v1.0.dat
1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f-0000000000000000000000000000000000000000000000000000000000000000-full-2-v1.0.dat
1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f-b5420e65846ded936d1e4855c066247fc461a3b281cd9e0e69f3cfa4df529ba2-delta-3-v1.0.dat
1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f-b5420e65846ded936d1e4855c066247fc461a3b281cd9e0e69f3cfa4df529ba2-full-3-v1.0.dat
1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f-d6d6b4d6bbd77aaa5927c8a21a1451b35f4860a7f9a58e51dae04037da9c08e8-delta-4-v1.0.dat
1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f-d6d6b4d6bbd77aaa5927c8a21a1451b35f4860a7f9a58e51dae04037da9c08e8-full-4-v1.0.dat
1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f-e488fa1bf0f712b224df0daf312b3d479f80e3a330d4bebd8f26a0d52dc0ebbb-delta-1-v1.0.dat
1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f-e488fa1bf0f712b224df0daf312b3d479f80e3a330d4bebd8f26a0d52dc0ebbb-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_testnet ~/.chia/mainnet/data_layer/db/server_files_location_testnet_bak
mkdir ~/.chia/mainnet/data_layer/db/server_files_location_testnet/
Next, restore the files:
chia data add_missing_files
Response:
None
Finally, verify that the files have been restored:
ls ~/.chia/mainnet/data_layer/db/server_files_location_testnet/
Response:
1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f-0000000000000000000000000000000000000000000000000000000000000000-delta-2-v1.0.dat
1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f-0000000000000000000000000000000000000000000000000000000000000000-full-2-v1.0.dat
1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f-b5420e65846ded936d1e4855c066247fc461a3b281cd9e0e69f3cfa4df529ba2-delta-3-v1.0.dat
1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f-b5420e65846ded936d1e4855c066247fc461a3b281cd9e0e69f3cfa4df529ba2-full-3-v1.0.dat
1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f-d6d6b4d6bbd77aaa5927c8a21a1451b35f4860a7f9a58e51dae04037da9c08e8-delta-4-v1.0.dat
1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f-d6d6b4d6bbd77aaa5927c8a21a1451b35f4860a7f9a58e51dae04037da9c08e8-full-4-v1.0.dat
1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f-e488fa1bf0f712b224df0daf312b3d479f80e3a330d4bebd8f26a0d52dc0ebbb-delta-1-v1.0.dat
1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f-e488fa1bf0f712b224df0daf312b3d479f80e3a330d4bebd8f26a0d52dc0ebbb-full-1-v1.0.dat
clear_pending_roots
Functionality: Clear pending roots that will not be published, associated data may not be recoverable
Usage: chia data clear_pending_roots [OPTIONS]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-i | --id | TEXT | True | The ID of the store from which to clear the pending roots |
--yes | None | False | Set to confirm the action without prompting [Default: not set / prompt to confirm] | |
-dp | --data-rpc-port | INTEGER | False | Set the port where the DataLayer is hosting the RPC interface. See rpc_port under data_layer in config.yaml |
-f | --fingerprint | INTEGER | False | Set the fingerprint to specify which wallet to use |
-h | --help | None | False | Show a help message and exit |
Example
To clear all pending roots, you need to enter the store ID. An example of this which also disables prompting:
chia data clear_pending_roots -i 2772c8108e19f9fa98ff7bc7d4bafd821319bc90af6b610d086b85f4c21fa816 --yes
Response:
{
"root": {
"generation": 1,
"node_hash": "e488fa1bf0f712b224df0daf312b3d479f80e3a330d4bebd8f26a0d52dc0ebbb",
"status": 1,
"tree_id": "2772c8108e19f9fa98ff7bc7d4bafd821319bc90af6b610d086b85f4c21fa816"
},
"success": true
}
create_data_store
Functionality: Create a data store. Triggers a Chia transaction
Usage: chia data create_data_store [OPTIONS]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-dp | --data-rpc-port | INTEGER | False | Set the port where the DataLayer is hosting the RPC interface. See rpc_port under data_layer in config.yaml |
-m | --fee | TEXT | False | Set the fees for the transaction, in XCH |
--verbose | None | False | Set to enable verbose output | |
-f | --fingerprint | INTEGER | False | Set the fingerprint to specify which wallet to use |
-h | --help | None | False | Show a help message and exit |
Example
Create a new data store:
chia data create_data_store -m 0.00001
Response:
{
'id': '1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f',
'success': True,
'txs':
[
{
'additions':
[
{
'amount': 1,
'parent_coin_info': '0xb4a1a658aaefd10930ecbccd51ac2c9a4853435b14acdb0de84729bfbefc791c',
'puzzle_hash': '0xeff07522495060c066f66f32acc2a77e3a3e737aca8baea4d1a64ea4cdc13da9'
},
{
'amount': 14999989999999,
'parent_coin_info': '0xb4a1a658aaefd10930ecbccd51ac2c9a4853435b14acdb0de84729bfbefc791c',
'puzzle_hash': '0x478255c372cec71557c20459f4b690fb1b7c57da3fcfc4b6396d78d9a396e384'
},
{
'amount': 1,
'parent_coin_info': '0x1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f',
'puzzle_hash': '0xd650e81d45c7381183c14c3363a81aa78cb3acfe213e46da26df75cd431557f9'
}
],
'amount': 1,
'confirmed': False,
'confirmed_at_height': 0,
'created_at_time': 1661141324,
'fee_amount': 10000000,
'memos': [],
'name': '0xaee362ae9d0ce3992b3bfb7cc48bde17f3d794cc383ff1d5e49a4d75dbf004d6',
'removals':
[
{
'amount': 15000000000000,
'parent_coin_info': '0x81fc1729bad3f19699461b1ee455a92493ef4c1d60ba37d22ac187a18367e08e',
'puzzle_hash': '0x221c0e9cd9b7f536e9a204ef93519e6c9d4b4c9a049bde8d66fa1816c23120d2'
},
{
'amount': 1,
'parent_coin_info': '0xb4a1a658aaefd10930ecbccd51ac2c9a4853435b14acdb0de84729bfbefc791c',
'puzzle_hash': '0xeff07522495060c066f66f32acc2a77e3a3e737aca8baea4d1a64ea4cdc13da9'
}
],
'sent': 10,
'sent_to': [],
'spend_bundle': {
'aggregated_signature': '0x8c431f07698ad69fd14ab04d77683801e6b908e441074f5ef5268350483d194a09a8b3cde681cb5c5fcf6444e0c9d4bf00999e8e6ad1522891baa590f82d92e2876b08e34b1f3156d0fe88ce206e5ed1567863e10a0397fd0a8a66bcbd5007b0',
'coin_spends':
[
{
'coin':
{
'amount': 15000000000000,
'parent_coin_info': '0x81fc1729bad3f19699461b1ee455a92493ef4c1d60ba37d22ac187a18367e08e',
'puzzle_hash': '0x221c0e9cd9b7f536e9a204ef93519e6c9d4b4c9a049bde8d66fa1816c23120d2'
},
'puzzle_reveal': '0xff02ffff01ff02ffff01ff02ffff03ff0bffff01ff02ffff03ffff09ff05ffff1dff0bffff1effff0bff0bffff02ff06ffff04ff02ffff04ff17ff8080808080808080ffff01ff02ff17ff2f80ffff01ff088080ff0180ffff01ff04ffff04ff04ffff04ff05ffff04ffff02ff06ffff04ff02ffff04ff17ff80808080ff80808080ffff02ff17ff2f808080ff0180ffff04ffff01ff32ff02ffff03ffff07ff0580ffff01ff0bffff0102ffff02ff06ffff04ff02ffff04ff09ff80808080ffff02ff06ffff04ff02ffff04ff0dff8080808080ffff01ff0bffff0101ff058080ff0180ff018080ffff04ffff01b0b3deeeb00319624e26767c5cf777cf9a02d046510181ed29f233e2847fa8ef28ede05d2770bb1b8f101ea8ae20527d61ff018080',
'solution': '0xff80ffff01ffff33ffa0eff07522495060c066f66f32acc2a77e3a3e737aca8baea4d1a64ea4cdc13da9ff0180ffff33ffa0478255c372cec71557c20459f4b690fb1b7c57da3fcfc4b6396d78d9a396e384ff860da47513597f80ffff34ff840098968080ffff3cffa084f72a9a3ce5152e1d627a259a0c1c90e6af389cb26af48173d84e374ecc518080ffff3dffa03a0ed375dff192685d1ef9a74424788b04655700bee898f0ea8445f8b55d38338080ff8080'
},
{
'coin':
{
'amount': 1,
'parent_coin_info': '0xb4a1a658aaefd10930ecbccd51ac2c9a4853435b14acdb0de84729bfbefc791c',
'puzzle_hash': '0xeff07522495060c066f66f32acc2a77e3a3e737aca8baea4d1a64ea4cdc13da9'
},
'puzzle_reveal': '0xff02ffff01ff04ffff04ff04ffff04ff05ffff04ff0bff80808080ffff04ffff04ff0affff04ffff02ff0effff04ff02ffff04ffff04ff05ffff04ff0bffff04ff17ff80808080ff80808080ff808080ff808080ffff04ffff01ff33ff3cff02ffff03ffff07ff0580ffff01ff0bffff0102ffff02ff0effff04ff02ffff04ff09ff80808080ffff02ff0effff04ff02ffff04ff0dff8080808080ffff01ff0bffff0101ff058080ff0180ff018080',
'solution': '0xffa0d650e81d45c7381183c14c3363a81aa78cb3acfe213e46da26df75cd431557f9ff01ffffa00000000000000000000000000000000000000000000000000000000000000000ffa0adcbcbaf4594e8d3057ea3a64a40560720ede80e720f867d2631069c27459de58080'
}
]
},
'to_puzzle_hash': '0x0202020202020202020202020202020202020202020202020202020202020202',
'trade_id': None,
'type': 0,
'wallet_id': 0
},
{
'additions':
[
{
'amount': 1,
'parent_coin_info': '0xb4a1a658aaefd10930ecbccd51ac2c9a4853435b14acdb0de84729bfbefc791c',
'puzzle_hash': '0xeff07522495060c066f66f32acc2a77e3a3e737aca8baea4d1a64ea4cdc13da9'
},
{
'amount': 14999989999999,
'parent_coin_info': '0xb4a1a658aaefd10930ecbccd51ac2c9a4853435b14acdb0de84729bfbefc791c',
'puzzle_hash': '0x478255c372cec71557c20459f4b690fb1b7c57da3fcfc4b6396d78d9a396e384'
}
],
'amount': 1,
'confirmed': False,
'confirmed_at_height': 0,
'created_at_time': 1661141324,
'fee_amount': 10000000,
'memos': [],
'name': '0xbb4cb461126d9ea9492e767462b9a4e408e497231c2093474cba2bcfe4397104',
'removals':
[
{
'amount': 15000000000000,
'parent_coin_info':
'0x81fc1729bad3f19699461b1ee455a92493ef4c1d60ba37d22ac187a18367e08e',
'puzzle_hash': '0x221c0e9cd9b7f536e9a204ef93519e6c9d4b4c9a049bde8d66fa1816c23120d2'
}
],
'sent': 0,
'sent_to': [],
'spend_bundle': None,
'to_puzzle_hash': '0xeff07522495060c066f66f32acc2a77e3a3e737aca8baea4d1a64ea4cdc13da9',
'trade_id': None,
'type': 1,
'wallet_id': 1
}
]
}
delete_mirror
Functionality: Delete a mirror, by coin_id
. Triggers a Chia transaction
Usage: chia data delete_mirror [OPTIONS]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-c | --coin_id | TEXT | True | The coin_id of the mirror to delete (obtainable from the get_mirrors command) |
-m | --fee | TEXT | False | Set the fees for the transaction, in XCH |
-dp | --data-rpc-port | INTEGER | False | Set the port where the DataLayer is hosting the RPC interface. See rpc_port under data_layer in config.yaml |
-f | --fingerprint | INTEGER | False | Set the fingerprint to specify which wallet to use |
-h | --help | None | False | Show a help message and exit |
Example
chia data delete_mirror -c b5756487c17fe3a2628e45a9d3d42e89231af718bb1735e6c8441e07ec005f9d -m 0.000001
Response:
{'success': True}
get_keys
Functionality: Get all keys associated with a store ID
Usage: chia data get_keys [OPTIONS]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-store | --id | TEXT | True | The hexadecimal store id |
-r | --root_hash | TEXT | False | The hexadecimal root hash |
-dp | --data-rpc-port | INTEGER | False | Set the port where the DataLayer is hosting the RPC interface. See rpc_port under data_layer in config.yaml |
-f | --fingerprint | INTEGER | False | Set the fingerprint to specify which wallet to use |
-p | --page | INTEGER | False | Enables pagination of the output and requests a specific page |
--max-page-size | INTEGER | False | Set how many bytes to be included in a page, if pagination is enabled [Default: 40 MB] | |
-h | --help | None | False | Show a help message and exit |
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 data get_keys --id 1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f
Response:
{
'keys': [
'0x0004',
'0x0005'
],
'success': True
}
get_keys_values
Functionality: Get all keys and values for a store. Must be subscribed to store ID
Usage: chia data get_keys_values [OPTIONS]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-store | --id | TEXT | True | The hexadecimal store id |
-r | --root_hash | TEXT | False | The hexadecimal root hash |
-dp | --data-rpc-port | INTEGER | False | Set the port where the DataLayer is hosting the RPC interface. See rpc_port under data_layer in config.yaml |
-f | --fingerprint | INTEGER | False | Set the fingerprint to specify which wallet to use |
-p | --page | INTEGER | False | Enables pagination of the output and requests a specific page |
--max-page-size | INTEGER | False | Set how many bytes to be included in a page, if pagination is enabled [Default: 40 MB] | |
-h | --help | None | False | Show a help message and exit |
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 data get_keys_values --id 1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f
Response:
{
'keys_values': [
{
'atom': None,
'hash': '0x26e60dd9b493eee1f6781fc13dd025e0bfafcde5a103c95dd087d91bd848d406',
'key': '0x0004',
'value': '0x0123456789abcdef'
},
{
'atom': None,
'hash': '0xc2dc94c2a85d7db4cfdd1d907bcc441c8fce595db2e2075b973fb8171e2f19a2',
'key': '0x0005',
'value': '0xbeadfeed'
}
],
'success': True
}
get_kv_diff
Functionality: Get the kv diff between two hashes within the same store ID
Usage: chia data get_kv_diff [OPTIONS]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-store | --id | TEXT | True | The hexadecimal store ID |
-hash_1 | --hash_1 | TEXT | True | The first hash to compare |
-hash_2 | --hash_2 | TEXT | True | The second hash to compare |
-dp | --data-rpc-port | INTEGER | False | Set the port where the DataLayer is hosting the RPC interface. See rpc_port under data_layer in config.yaml |
-f | --fingerprint | INTEGER | False | Set the fingerprint to specify which wallet to use |
-p | --page | INTEGER | False | Enables pagination of the output and requests a specific page |
--max-page-size | INTEGER | False | Set how many bytes to be included in a page, if pagination is enabled [Default: 40 MB] | |
-h | --help | None | False | Show a help message and exit |
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 data get_kv_diff --id 1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f -hash_1 0x26e60dd9b493eee1f6781fc13dd025e0bfafcde5a103c95dd087d91bd848d406 -hash_2 0xc2dc94c2a85d7db4cfdd1d907bcc441c8fce595db2e2075b973fb8171e2f19a2
Response:
{
'diff': [
{
'key': '0005',
'type': 'INSERT',
'value': 'beadfeed'
},
{
'key': '0004',
'type': 'DELETE',
'value': '0123456789abcdef'
}
],
'success': True
}
get_mirrors
Functionality: List all mirrors for a store ID
Usage: chia data get_mirrors [OPTIONS]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-i | --id | TEXT | True | The hexadecimal ID of the store for which to get mirrors |
-dp | --data-rpc-port | INTEGER | False | Set the port where the DataLayer is hosting the RPC interface. See rpc_port under wallet in config.yaml |
-f | --fingerprint | INTEGER | False | Set the fingerprint to specify which wallet to use |
-h | --help | None | False | Show a help message and exit |
Example
chia data get_mirrors -i 1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f
Response:
{
'mirrors': [
{
'amount': 1000,
'coin_id': 'b5756487c17fe3a2628e45a9d3d42e89231af718bb1735e6c8441e07ec005f9d',
'launcher_id': '1a119374fc7d7055d3419fdcd7f93065f28a1e4acacdf9c73b933b27b685550f',
'ours': True,
'urls': [
'http://www.example.com:8575',
'http://www.example2.com:8575'
]
}
],
'success': True
}
get_owned_stores
Functionality: Get owned stores
Usage: chia data get_owned_stores [OPTIONS]
Options:
Short Command | Long Command | Type | Required | Description |
---|---|---|---|---|
-dp | --data-rpc-port | INTEGER | False | Set the port where the DataLayer is hosting the RPC interface. See rpc_port under wallet in config.yaml |
-f | --fingerprint | INTEGER | False | Set the fingerprint to specify which wallet to use |
-h | --help | None | False | Show a help message and exit |
Example
chia data get_owned_stores
Response:
{
'store_ids': [
'39114b28a3674b6c2c0ed65d3518842fd17f9df46794f49cd223f9f3a463f09d',
'5d8f5c88f27804f5c387e070403faece14acb74460bbf7d47739178a3774eff3',
'77e9c21be435dded6e8c9b32e93b2b880665f5b34f860a642f22d3fa500ce457',
'9d0c65e77c750eac28b3fa78e57cdcec59fe53448eb59bdfbfa694d89f262b4b'
],
'success': True
}