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:

# account name vRAM table exists on
export CONTRACT_NAME= 
# run script
node zeus_boxes/ipfs-dapp-service/utils/ipfs-service/get-table

Optional env variables (if using non-local nodeos / IPFS instance):

# defaults to all vRam tables in the abi, can be used to target a specific table
export TABLE_NAME=
# defaults to localhost:8888, can be used to specify external nodeos instance
export NODEOS_ENDPOINT=
# defaults to localhost, can be used to specify external IPFS instance
export IPFS_HOST=
# defaults to 5001
export IPFS_PORT=
# defaults to http
export IPFS_PROTOCOL=
# defaults to 1024
export SHARD_LIMIT=
# defaults to false
# produces a ${contractName}-${tableName}-roots.json file which is the table's current entries
# also produces an ipfs-data.json which can be used to recreate the current state of the IPFS table
export VERBOSE=

Steps to produce /ipfs-dapp-service/test1-test-table.json file below:

npm i -g @liquidapps/zeus-cmd
mkdir ipfs-dapp-service; cd ipfs-dapp-service
zeus box create
zeus unbox ipfs-dapp-service
zeus test -c
export CONTRACT_NAME=test1
node zeus_boxes/ipfs-dapp-service/utils/ipfs-service/get-table

Expected output /ipfs-dapp-service/test1-test-table.json:

[
  {
    "scope": "test1",
    "key": "2b02000000000000",
    "data": {
      "id": "555",
      "sometestnumber": "0"
    }
  },
  {
    "scope": "test1",
    "key": "0200000000000000",
    "data": {
      "id": "2",
      "sometestnumber": "0"
    }
  }
  ...
]

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

[
  {
    "shard_uri": "01551220d0c889cbd658f2683c78a09a8161ad406dd828dadab383fdcc0659aa6dfed8dc",
    "shard": 3
  },
  {
    "shard_uri": "01551220435f234b3af595737af50ac0b4e44053f0b31d31d94e1ffe917fd3dfbc6a9d88",
    "shard": 156
  },
  ...
]

ipfs-data.json - produces all data necessary to recreate current state of the table, can be used for populating a DSP’s IPFS cluster

{
  "015512204cbbd8ca5215b8d161aec181a74b694f4e24b001d5b081dc0030ed797a8973e0": "01000000000000000000000000000000",
  "01551220b422e3b9180b32ba0ec0d538c7af1cf7ccf764bfb89f4cd5bc282175391e02bb": "77cc0000000000007f00000000000000",
  ...
}

Last updated