How to get coin activities of type by block
Prerequisites
Before getting started, make sure you have the following ready:
- Node v.14+
- NPM
Step 1: Setup Blocklens
First register your Blocklens account and get your Blocklens API Key.
Once you have your Blocklens API Key, install the Blocklens SDK in your project.
npm i blocklens-sdk
Step 2: Get coin activities of type by block
In order to get coin activities of type by block, Blocklens provides you a getCoinActivitiesOfTypeByBlock endpoint to do so.
Here you'll need parameters: block_height
, coin_type
.
Once you've obtained all the block_height
, coin_type
, you can copy the following code:
import Blocklens from "blocklens-sdk";
const blocklens = new Blocklens();
blocklens.init({ apiKey: "YOUR_API_KEY" });
const runApis = async () => {
const response = await blocklens.APTOS_MAINNET.getCoinActivitiesOfTypeByBlock("18246150", "0x1::aptos_coin::AptosCoin");
console.log(response);
};
runApis();
Step 3: Run the script
ts-node index.ts
In your terminal, you should see the following JSON response with the data: In your terminal, you should see the following JSON response with the data blocks:
[
{
"cursor": "string",
"page": 0,
"limit": 0,
"total_items": 0,
"data": [
{
"transaction_version": 46292538,
"event_index": 1,
"amount": 1500000000,
"block_height": 15747799,
"coin_type": "0x6de517a18f003625e7fba9b9dc29b310f2e3026bbeb1997b3ada9de1e3cec8d6::opc::OPC",
"activity_type": "0x1::coin::DepositEvent",
"entry_function_id_str": "0x6de517a18f003625e7fba9b9dc29b310f2e3026bbeb1997b3ada9de1e3cec8d6::opc::transfer",
"event_account_address": "0x673afeeb37ccba25508b82d3647876446e177de2b71d488c0704e0a0a6ba5711",
"event_sequence_number": 1,
"is_gas_fee": true,
"is_transaction_success": true,
"owner_address": "0x673afeeb37ccba25508b82d3647876446e177de2b71d488c0704e0a0a6ba5711",
"block_time": "2023-06-19 23:25:05.006",
"timestamp": 1,
"event_creation_number": 2
}
]
}
]
Congratulations 🥳 you just found the get coin activities of type by block on multiple chains with only a few lines of code using the Blocklens Wallet API!
API Reference
If you want to know more details on the endpoint and optional parameters, check out:
Support
If you face any trouble following the tutorial, feel free to reach out to our community engineers in our Discord or Forum to get 24/7 developer support.