Get table

Get table - get-table.js

Reads all vRAM tables of a smart contract and stores them with the naming syntax: ${contract_name}-${table_name}-table.json. The script is located in the utils/ipfs-service/get-table.js of an unboxed zeus box.
Mandatory env variables:
1
# account name vRAM table exists on
2
export CONTRACT_NAME=
3
# run script
4
node zeus_boxes/ipfs-dapp-service/utils/ipfs-service/get-table
Copied!
Optional env variables (if using non-local nodeos / IPFS instance):
1
# defaults to all vRam tables in the abi, can be used to target a specific table
2
export TABLE_NAME=
3
# defaults to localhost:8888, can be used to specify external nodeos instance
4
export NODEOS_ENDPOINT=
5
# defaults to localhost, can be used to specify external IPFS instance
6
export IPFS_HOST=
7
# defaults to 5001
8
export IPFS_PORT=
9
# defaults to http
10
export IPFS_PROTOCOL=
11
# defaults to 1024
12
export SHARD_LIMIT=
13
# defaults to false
14
# produces a ${contractName}-${tableName}-roots.json file which is the table's current entries
15
# also produces an ipfs-data.json which can be used to recreate the current state of the IPFS table
16
export VERBOSE=
Copied!
Steps to produce /ipfs-dapp-service/test1-test-table.json file below:
1
npm i -g @liquidapps/zeus-cmd
2
mkdir ipfs-dapp-service; cd ipfs-dapp-service
3
zeus box create
4
zeus unbox ipfs-dapp-service
5
zeus test -c
6
export CONTRACT_NAME=test1
7
node zeus_boxes/ipfs-dapp-service/utils/ipfs-service/get-table
Copied!
Expected output /ipfs-dapp-service/test1-test-table.json:
1
[
2
{
3
"scope": "test1",
4
"key": "2b02000000000000",
5
"data": {
6
"id": "555",
7
"sometestnumber": "0"
8
}
9
},
10
{
11
"scope": "test1",
12
"key": "0200000000000000",
13
"data": {
14
"id": "2",
15
"sometestnumber": "0"
16
}
17
}
18
...
19
]
Copied!
If VERBOSE=true, you will also get test1-test-roots.json and ipfs-data.json:
test1-test-roots.json - equivalent of cleos get table test1 test1 test
1
[
2
{
3
"shard_uri": "01551220d0c889cbd658f2683c78a09a8161ad406dd828dadab383fdcc0659aa6dfed8dc",
4
"shard": 3
5
},
6
{
7
"shard_uri": "01551220435f234b3af595737af50ac0b4e44053f0b31d31d94e1ffe917fd3dfbc6a9d88",
8
"shard": 156
9
},
10
...
11
]
Copied!
ipfs-data.json - produces all data necessary to recreate current state of the table, can be used for populating a DSP’s IPFS cluster
1
{
2
"015512204cbbd8ca5215b8d161aec181a74b694f4e24b001d5b081dc0030ed797a8973e0": "01000000000000000000000000000000",
3
"01551220b422e3b9180b32ba0ec0d538c7af1cf7ccf764bfb89f4cd5bc282175391e02bb": "77cc0000000000007f00000000000000",
4
...
5
}
Copied!
Copy link