Sendblocks Key-Value Indexer Quickstart

Indexing BAYC token transfer events made easy

The following instructions will guide you in deploying a quick Key-Value Storage of contract events that can be publicly sharable



  1. npm install --global sendblocks-cli

  2. sb-cli login


  3. sb-cli deploy

    Expected result:

    Found 1 yaml files in src folder
     - functions.yaml
    Comparing state...
    Webhooks:
     - To be created:
    ┌─────────┬────────────────┬───────────────────────┐
    │ (index) │ webhook_name   │ url                   │
    ├─────────┼────────────────┼───────────────────────┤
    │ 0       │ 'test_webhook' │ 'https://example.com' │
    └─────────┴────────────────┴───────────────────────┘
    Functions:
     - To be created:
    ┌─────────┬─────────────────┬─────────────────────┬────────────────────────┬────────────────┬─────────────────────────┐
    │ (index) │ function_name   │ chain_id            │ trigger_types          │ webhook        │ should_send_std_streams │
    ├─────────┼─────────────────┼─────────────────────┼────────────────────────┼────────────────┼─────────────────────────┤
    │ 0       │ 'bayc-function' │ 'CHAIN_ETH_MAINNET' │ 'TRIGGER_TYPE_ADDRESS' │ 'test_webhook' │ true                    │
    └─────────┴─────────────────┴─────────────────────┴────────────────────────┴────────────────┴─────────────────────────┘
    

    Confirm (click 'y'):

    Please confirm that you have reviewed the changes and want to proceed with the deployment › (y/N)
    

    Expected result:

    Deploying changes...
    
    Creating webhook test_webhook...
    Creating function bayc-function...
    
    Deployment complete!
    
    Webhook deployment results:
    ┌─────────┬────────────────┬────────────────────────────────────────┬──────────┬─────────┬──────────┐
    │ (index) │ webhook_name   │ webhook_id                             │ deployed │ skipped │ response │
    ├─────────┼────────────────┼────────────────────────────────────────┼──────────┼─────────┼──────────┤
    │ 0       │ 'test_webhook' │ '12345678-1234-1234-1234-1234567890'   │ true     │         │          │
    └─────────┴────────────────┴────────────────────────────────────────┴──────────┴─────────┴──────────┘
    Function deployment results:
    ┌─────────┬─────────────────┬────────────────────────────────────────┬──────────┬─────────┬──────────┐
    │ (index) │ function_name   │ function_id                            │ deployed │ skipped │ response │
    ├─────────┼─────────────────┼────────────────────────────────────────┼──────────┼─────────┼──────────┤
    │ 0       │ 'bayc-function' │ '1234565-1234-1234-1234-1234567890'    │ true     │         │          │
    └─────────┴─────────────────┴────────────────────────────────────────┴──────────┴─────────┴──────────┘
    

  4. Replay a block with BAYC transfers -

    https://docs.sendblocks.io/reference/replay_blocks_api_v1_functions_replay_blocks_post
    Copy the function_id here and run (don't forget to copy also the AccessToken):

    curl --request POST \
         --url https://api.sendblocks.io/api/v1/functions/replay_blocks \
         --header 'accept: application/json' \
         --header 'authorization: Bearer COPY_YOUR_ACCESS_TOKEN_HERE' \
         --header 'content-type: application/json' \
         --data '
    {
      "chain_id": "CHAIN_ETH_MAINNET",
      "xl_flag": false,
      "start_block_number": 20404113,
      "end_block_number": 20404113,
      "functions": [
        "COPY_YOUR_FUNCTION_ID_HERE"
      ]
    }
    '
    

    Expected response:

    OK
    
  5. Get your namespace id (don't forget to copy your bearer token)

    https://docs.sendblocks.io/reference/list_tenant_namespaces_api_v1_storage_namespaces_get

    curl --request GET \
         --url https://api.sendblocks.io/api/v1/storage/namespaces \
         --header 'accept: application/json' \
         --header 'authorization: Bearer COPY_YOUR_ACCESS_TOKEN_HERE'
    

    Expected response:

    [
      "BAYC-storage"
    ]
    

  6. Get the current Key-Value storage (don't forget to copy your bearer token)

    https://docs.sendblocks.io/reference/get_namespace_storage_api_v1_storage_namespaces**namespace_id**values_get

    curl --request GET \
         --url https://api.sendblocks.io/api/v1/storage/namespaces/BAYC-storage/values \
         --header 'accept: application/json' \
         --header 'authorization: Bearer COPY_YOUR_ACCESS_TOKEN_HERE '
    

    Expected response:

    {
      "token-0x212d": "{\"owner\":\"0x79c6A33283774C694dDfae570081D38F6849E5be\",\"previousOwner\":\"0x194EaC8180177c5261dF925B872e0b29CEd2f54E\",\"approved\":\"0x0000000000000000000000000000000000000000\",\"tokenId\":\"0x212d\"}"
    }
    
  7. Create Public Share (optional)

    https://docs.sendblocks.io/reference/create_public_share_api_v1_storage_namespaces**namespace_id**shares_post
    Run:

    curl --request POST \
         --url https://api.sendblocks.io/api/v1/storage/namespaces/BAYC-storage/shares \
         --header 'accept: application/json' \
         --header 'authorization: Bearer COPY_YOUR_ACCESS_TOKEN_HERE' \
         --header 'content-type: application/json' \
         --data '
    {
      "enabled": true,
      "description": "This is a public share"
    }
    '
    

    Expected response:

    {
      "public_share_id": "12345678-1234-1234-1234-1234567890"
    }
    

  1. Get Public Share (optional)

    https://docs.sendblocks.io/reference/get_public_share_api_v1_storage_namespaces**namespace_id**shares**id**get
    Copy the public_share_id and run:

    curl --request GET \
         --url https://api.sendblocks.io/api/v1/storage/namespaces/BAYC-storage/shares/8e004cb3-db60-4637-bf92-bbfdb248d4ee \
         --header 'accept: application/json' \
         --header 'authorization: Bearer COPY_YOUR_ACCESS_TOKEN_HERE'
    

    Expected response

    {
      "public_share_id": "123456789-1234-1234-1234-1234567890",
      "namespace_id": "BAYC-storage",
      "description": "This is a public share",
      "enabled": true,
      "url": "http://api.sendblocks.io/public/123456789-1234-1234-1234-1234567890"
    }
    
  2. Data Request

Run the following to query the data from the public share

curl --request GET \
     --url https://api.sendblocks.io/public/123456789-1234-1234-1234-1234567890\
     --header 'accept: application/json'

😃