Block Module
Block module for accessing blockchain block data.
To learn more about how to use the AI Agent SDK to interact with the wallet module, please visit AI Agent SDK Block Information.
4.1 Get Current Block
Get the current latest block.
Function Name
get_currentExample Code
from crypto_com_developer_platform_client import Block block = Block.get_current() print(block)
Returns
The latest block data.Errors
ValueError: If the Block class is not initialized with a Client instance.Example Return
{'status': 'Success', 'data': {'blockNumber': example-block-number}}
Function Name
getCurrentBlockExample Code
import { Block } from '@crypto.com/developer-platform-client'; const block = await Block.getCurrentBlock(); console.log(block);
Returns
Promise<ApiResponse<BlockNumber>>: A promise that resolves to the current block data.Example Return
{ status: 'Success', data: { blockNumber: example-number } }
4.2 Get Block By Tag
Get a block by tag or block number.
Function Name
get_by_tagArguments
tag (str): Integer of a block number in hex, or the string "earliest", "latest" or "pending", as in https://ethereum.org/en/developers/docs/apis/json-rpc/#default-block tx_detail (str): If true it returns the full transaction objects, if false only the hashes of the transactions.Example Code
from crypto_com_developer_platform_client import Block block = Block.get_by_tag("latest", "true") print(block)
Returns
The block data.Errors
ValueError: If the Block class is not initialized with a Client instance.Example Return
{'status': 'Success', 'data': {'block': {'_type': 'Block', 'baseFeePerGas': 'example-fee', 'difficulty': 'example-difficulty', 'extraData': 'example-data', 'gasLimit': 'example-gas-limit', 'gasUsed': 'example-gas-used', 'blobGasUsed': 'example-blob-gas-used', 'excessBlobGas': 'example-gas', 'hash': 'example-hash', 'miner': 'example-address', 'prevRandao': 'example-randao', 'nonce': 'example-nonce', 'number': example-number, 'parentHash': 'example-hash', 'timestamp': example-timestamp, 'parentBeaconBlockRoot': 'example-hash', 'stateRoot': 'example-hash', 'receiptsRoot': 'example-hash', 'transactions': ['example-transactions']}}}
Function Name
getBlockByTagArguments
(string} blockTag: Block identifier ('latest', 'pending', or block number in hex). {string} txDetail: Whether to include transaction details ('true' or 'false').Example Code
import { Block } from '@crypto.com/developer-platform-client'; const block = await Block.getBlockByTag('latest', 'true'); console.log(block);
Returns
Promise<ApiResponse<BlockData>>: A promise that resolves to the block data.Example Return
{ status: 'Success', data: { block: { _type: 'Block', baseFeePerGas: 'example-fee', difficulty: 'example-difficulty', extraData: 'example-data', gasLimit: 'example-gas-limit', gasUsed: 'example-gas-used', blobGasUsed: example-gas, excessBlobGas: example-gas, hash: 'example-hash', miner: 'example-hash', prevRandao: 'example-hash', nonce: 'example-nonce', number: example-number, parentHash: 'example-hash', timestamp: example-timestamp, parentBeaconBlockRoot: example-block-root, stateRoot: 'example-hash', receiptsRoot: 'example-hash', transactions: [example-transaction-array] } } }
Last updated
Was this helpful?