Skip to content

Files

Latest commit

 

History

History
287 lines (215 loc) · 22.2 KB

File metadata and controls

287 lines (215 loc) · 22.2 KB

Blocks

(data.evm.blocks)

Overview

Available Operations

listLatestBlocksAllChains

Lists the most recent blocks from all supported EVM-compatible chains. The results can be filtered by network.

Example Usage

import { AvaCloudSDK } from "@avalabs/avacloud-sdk";

const avaCloudSDK = new AvaCloudSDK({
  serverURL: "https://api.example.com",
  chainId: "43114",
  network: "mainnet",
});

async function run() {
  const result = await avaCloudSDK.data.evm.blocks.listLatestBlocksAllChains({
    network: "mainnet",
  });

  for await (const page of result) {
    // Handle the page
    console.log(page);
  }
}

run();

Standalone function

The standalone function version of this method:

import { AvaCloudSDKCore } from "@avalabs/avacloud-sdk/core.js";
import { dataEvmBlocksListLatestBlocksAllChains } from "@avalabs/avacloud-sdk/funcs/dataEvmBlocksListLatestBlocksAllChains.js";

// Use `AvaCloudSDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const avaCloudSDK = new AvaCloudSDKCore({
  serverURL: "https://api.example.com",
  chainId: "43114",
  network: "mainnet",
});

async function run() {
  const res = await dataEvmBlocksListLatestBlocksAllChains(avaCloudSDK, {
    network: "mainnet",
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  for await (const page of result) {
    // Handle the page
    console.log(page);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.ListLatestBlocksAllChainsRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.
options.serverURL string An optional server URL to use.

Response

Promise<operations.ListLatestBlocksAllChainsResponse>

Errors

Error Type Status Code Content Type
errors.BadRequest 400 application/json
errors.Unauthorized 401 application/json
errors.Forbidden 403 application/json
errors.NotFound 404 application/json
errors.TooManyRequests 429 application/json
errors.InternalServerError 500 application/json
errors.BadGateway 502 application/json
errors.ServiceUnavailable 503 application/json
errors.SDKError 4XX, 5XX */*

getLatestBlocks

Lists the latest indexed blocks on the EVM-compatible chain sorted in descending order by block timestamp.

Example Usage

import { AvaCloudSDK } from "@avalabs/avacloud-sdk";

const avaCloudSDK = new AvaCloudSDK({
  serverURL: "https://api.example.com",
  chainId: "43114",
  network: "mainnet",
});

async function run() {
  const result = await avaCloudSDK.data.evm.blocks.getLatestBlocks({
    chainId: "43114",
  });

  for await (const page of result) {
    // Handle the page
    console.log(page);
  }
}

run();

Standalone function

The standalone function version of this method:

import { AvaCloudSDKCore } from "@avalabs/avacloud-sdk/core.js";
import { dataEvmBlocksGetLatestBlocks } from "@avalabs/avacloud-sdk/funcs/dataEvmBlocksGetLatestBlocks.js";

// Use `AvaCloudSDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const avaCloudSDK = new AvaCloudSDKCore({
  serverURL: "https://api.example.com",
  chainId: "43114",
  network: "mainnet",
});

async function run() {
  const res = await dataEvmBlocksGetLatestBlocks(avaCloudSDK, {
    chainId: "43114",
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  for await (const page of result) {
    // Handle the page
    console.log(page);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.GetLatestBlocksRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.
options.serverURL string An optional server URL to use.

Response

Promise<operations.GetLatestBlocksResponse>

Errors

Error Type Status Code Content Type
errors.BadRequest 400 application/json
errors.Unauthorized 401 application/json
errors.Forbidden 403 application/json
errors.NotFound 404 application/json
errors.TooManyRequests 429 application/json
errors.InternalServerError 500 application/json
errors.BadGateway 502 application/json
errors.ServiceUnavailable 503 application/json
errors.SDKError 4XX, 5XX */*

getBlock

Gets the details of an individual block on the EVM-compatible chain.

Example Usage

import { AvaCloudSDK } from "@avalabs/avacloud-sdk";

const avaCloudSDK = new AvaCloudSDK({
  serverURL: "https://api.example.com",
  chainId: "43114",
  network: "mainnet",
});

async function run() {
  const result = await avaCloudSDK.data.evm.blocks.getBlock({
    chainId: "43114",
    blockId: "0x17533aeb5193378b9ff441d61728e7a2ebaf10f61fd5310759451627dfca2e7c",
  });

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { AvaCloudSDKCore } from "@avalabs/avacloud-sdk/core.js";
import { dataEvmBlocksGetBlock } from "@avalabs/avacloud-sdk/funcs/dataEvmBlocksGetBlock.js";

// Use `AvaCloudSDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const avaCloudSDK = new AvaCloudSDKCore({
  serverURL: "https://api.example.com",
  chainId: "43114",
  network: "mainnet",
});

async function run() {
  const res = await dataEvmBlocksGetBlock(avaCloudSDK, {
    chainId: "43114",
    blockId: "0x17533aeb5193378b9ff441d61728e7a2ebaf10f61fd5310759451627dfca2e7c",
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

Parameter Type Required Description
request operations.GetBlockRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.
options.serverURL string An optional server URL to use.

Response

Promise<components.GetEvmBlockResponse>

Errors

Error Type Status Code Content Type
errors.BadRequest 400 application/json
errors.Unauthorized 401 application/json
errors.Forbidden 403 application/json
errors.NotFound 404 application/json
errors.TooManyRequests 429 application/json
errors.InternalServerError 500 application/json
errors.BadGateway 502 application/json
errors.ServiceUnavailable 503 application/json
errors.SDKError 4XX, 5XX */*