Rollup Data SDK

Introduction to using the SDK for Rollup Data

📘

Rollup Keys

List of all Rollup Data keys can be pulled from API, endpoint: /keys/layer2

Umbrella SDK allows developers to interact with the Umbrella Network and fetch data/proofs they require to build the application. To understand how Merkle Trees help Umbrella, make sure you read the Introduction to Layer-2 Data article.

The first step to interact with the Rollup Data SDK should be to setup the required environment for interacting with the SDK.

There are 2 critical components of setting up the environment :

1.) Ensure you have Umbrella API token ready
2.) Ensure you have the latest SDK installed

Using the APIClient , you can fetch the latest blocks or can fetch the leaves of the block using the function getLeavesOfBlock. The leaves of the response represent the available Layer-2 data nodes and then the object of the required pair can be further opened to get other relevant information like the Proof or Value.

APIClient

Initialization

import {ContractRegistry, ChainContract, APIClient} from '@umb-network/toolbox';

const chainContractAddress = new ContractRegistry(provider, contractRegistryAddress).getAddress('Chain');
const chainContract = new ChainContract(provider, chainContractAddress);

const apiClient = new APIClient({
  apiKey: 'xxx',
  baseURL: 'https://sanctuary-playground-api.network/api/',
  chainContract,
});

APIClient#getBlocks

Signature

apiClient.getBlocks(options ? : {offset? : number; limit? : number}): Promise<IChainBlock[]>;

Examples

Code:

await apiClient.getBlocks();
await apiClient.getBlocks({offset: 10, limit: 10});

Response example:

[
  {
    "staked": "3000000000000000000",
    "power": "3000000000000000000",
    "voters": [
      "0x998cb7821e605cC16b6174e7C50E19ADb2Dd2fB0",
      "0xDc3eBc37DA53A644D67E5E3b5BA4EEF88D969d5C"
    ],
    "votes": {
      "0x998cb7821e605cC16b6174e7C50E19ADb2Dd2fB0": "2000000000000000000",
      "0xDc3eBc37DA53A644D67E5E3b5BA4EEF88D969d5C": "1000000000000000000"
    },
    "_id": "block::8681",
    "blockId": 8681,
    "__v": 1,
    "chainAddress": "0xc94A585C1bC804C03A864Ee766Dd1B432f73f9A8",
    "dataTimestamp": "2021-05-14T11:57:02.000Z",
    "root": "0x08dc10051a87f6ee6856f1758a2b4921e43aa257e9c346b6bb6e8a3f21f531e1",
    "status": "finalized",
    "anchor": "8833714",
    "minter": "0x998cb7821e605cC16b6174e7C50E19ADb2Dd2fB0"
  }
]

APIClient#getNewestBlock

Signature

apiClient.getNewestBlock(): Promise<IChainBlock>;

Examples

Code:

await apiClient.getNewestBlock();

Response example:

{
  "staked": {
    "type": "BigNumber",
    "hex": "0x6124fee993bc0000"
  },
  "power": {
    "type": "BigNumber",
    "hex": "0x4563918244f40000"
  },
  "voters": [
    "0x998cb7821e605cC16b6174e7C50E19ADb2Dd2fB0",
    "0xDc3eBc37DA53A644D67E5E3b5BA4EEF88D969d5C"
  ],
  "votes": {
    "0x998cb7821e605cC16b6174e7C50E19ADb2Dd2fB0": "2000000000000000000",
    "0xDc3eBc37DA53A644D67E5E3b5BA4EEF88D969d5C": "3000000000000000000"
  },
  "_id": "block::120539",
  "blockId": 120539,
  "__v": 1,
  "chainAddress": "0x41f16D60C58a0D13C89149A1675c0ca39e170EDD",
  "dataTimestamp": "2021-05-23T14:01:52.000Z",
  "root": "0xde1f03f6e568365db09e6e4a826f2591c32d393bd64dc6998fa4ec86b6dd2c3e",
  "status": "finalized",
  "anchor": {
    "type": "BigNumber",
    "hex": "0x017db636"
  },
  "minter": "0x998cb7821e605cC16b6174e7C50E19ADb2Dd2fB0"
}

APIClient#getBlock

Signature

apiClient.getBlock(blockId: string): Promise<IChainBlock>;

Examples

Code:

await apiClient.getBlock(350); // {...}

Response example: same as for getNewestBlock

APIClient#getLeavesOfBlock

API: /blocks/8683/leaves

Signature

apiClient.getLeavesOfBlock(blockId: string): Promise<IBlockLeafWithProof[]>;

Examples

Code:

await apiClient.getLeavesOfBlock(350);

Response example:

[
  {
    "proof": [
      "0xb01d5b067b172ba0a361cf7fe7375a55a727dd1a20834f0962185f37b8981371",
      "0x3b113a401b261dfb04166a9c652af63ccb6d77a5db0b4c0d127ecbc306fdb990",
      "0xda4a6c7a5f7414401f4cb34a536518ad48ee742797506650249bcc34774c5f41",
      "0x96c4d220b2697326a21d3ef00c1cb5fd1afd1724acfca4d78c4d8bd79c32e775",
      "0x71b12dff5ec4202dbe8d7352b36058e883025859097aa17400c347d49edba62c",
      "0x006dca779b13b296942d266433327c4c35f5122419474a753d854ce2ebe0c271",
      "0xb8aa806a9e49fff22eab7f86c56584db8084c6fbbbef8c9a8a5ef35607be72c2"
    ],
    "_id": "block::120536::leaf::ADA-BTC",
    "blockId": "120536",
    "key": "ADA-BTC",
    "__v": 0,
    "value": "0x00000000000000000000000000000000000000000000000000001fe0b6cca400"
  }
]

APIClient#getProofs

Signature

apiClient.getProofs(keys: string[]): Promise<IProofs | null>;

Examples

Code:

await apiClient.getProofs("ETH-USD");

Response example:

{
  "block": {
    "staked": {
      "type": "BigNumber",
      "hex": "0x6124fee993bc0000"
    },
    "power": {
      "type": "BigNumber",
      "hex": "0x4563918244f40000"
    },
    "voters": [
      "0x998cb7821e605cC16b6174e7C50E19ADb2Dd2fB0",
      "0xDc3eBc37DA53A644D67E5E3b5BA4EEF88D969d5C"
    ],
    "votes": {
      "0x998cb7821e605cC16b6174e7C50E19ADb2Dd2fB0": "2000000000000000000",
      "0xDc3eBc37DA53A644D67E5E3b5BA4EEF88D969d5C": "3000000000000000000"
    },
    "_id": "block::120541",
    "blockId": 120541,
    "__v": 1,
    "chainAddress": "0x41f16D60C58a0D13C89149A1675c0ca39e170EDD",
    "dataTimestamp": "2021-05-23T14:03:52.000Z",
    "root": "0x9984950d3ac4bd4e98912db7aeb91c8bc1a50a0af84b9c0d99249ff46d5a1b06",
    "status": "finalized",
    "anchor": {
      "type": "BigNumber",
      "hex": "0x017db652"
    },
    "minter": "0x998cb7821e605cC16b6174e7C50E19ADb2Dd2fB0"
  },
  "keys": [
    "ADA-BTC",
    "ADA-USD",
    "ADA-USDT",
    "AMPL-USD-VWAP-1day",
    "ATOM-USDT",
    "BCH-BTC",
    "BNB-BTC",
    "BNB-BUSD",
    "BNB-USD",
    "BNT-USD"
  ],
  "leaves": [
    {
      "proof": [
        "0x4ea61613b7559f7f90d5ec5758268d9db4b40d285bb91f0836a482db86108c9c",
        "0x31c294d7875566fddab273247575b0cf746f46959efacd1cbae0bc363bed8a44",
        "0x2a3169d555d173f035ba472e902fe20740cbd48c13e72aaac0971021dbc35ad6",
        "0x0f6e1194a152d1bd86404ab8a6ebd9d499e1536c8c9e9d3387bdbe0ab3afacd0",
        "0xc8dcc3b734fa40f1f0bf5fe83f4edaf0e6646169400f3f6bf3cfbf601cb5ab93",
        "0xf3a886434970e44c0d1beae167e14e5ce150fefa3205f0a5f1fcc4a7f9518514",
        "0x03181c924011b0f040e13936715134692e48b13d3c85929f960356e9c94e0fe7"
      ],
      "_id": "block::120541::leaf::ADA-BTC",
      "blockId": "120541",
      "key": "ADA-BTC",
      "__v": 0,
      "value": "0x00000000000000000000000000000000000000000000000000001fe0b6cca400"
    }
  ]
}

APIClient#verifyProofForNewestBlock

Signature

async verifyProofForNewestBlock < T extends string | number = string | number > 
  (key: string): Promise <{ success: boolean, value: T, dataTimestamp: Date }>

Examples

Code:

await apiClient.verifyProofForNewestBlock("ETH-USD");

Response example for successful verification:

{
  success: true,
  value: 1254.24,
  dataTimestamp: "2020-05-14T13:34: 08.000Z"
}

For unsuccessful it throws.