@evmexplorer/blockscout
TypeScript icon, indicating that this package has built-in type declarations

0.0.22 • Public • Published

EVMExplorer-Blockscout

EVM Explorer TypeScript Blockscout v2 sdk.

📚 Install

npm install @evmexplorer/blockscout

or

yarn add @evmexplorer/blockscout

Using EVMExplorer-Blockscout SDK

Fetching a Transaction

To fetch a transaction on Ethereum mainnet as demonstrated on Ethereum Stack Oveflow answer:

import type { TransactionBlockscout } from '@evmexplorer/blockscout';
import { fetchTransactionBlockscout } from '@evmexplorer/blockscout';

const data: TransactionBlockscout = await fetchTransactionBlockscout(
  '0xdc7ddf3d0e53532eeeda7a7a99c88255ccee5a3b4404441278cbbd79b4c85086',
);

console.log(data);

Output

The fetchTransactionBlockscout function returns an object with the following properties:

{
  priority_fee: '70439166556560',
  tx_burnt_fee: '676806248593230',
  raw_input: '0xa22cb4650000000000000000000000001e0049783f008a0085193e00003d00cd54003c710000000000000000000000000000000000000000000000000000000000000001',
  result: 'success',
  hash: '0xdc7ddf3d0e53532eeeda7a7a99c88255ccee5a3b4404441278cbbd79b4c85086',
  max_fee_per_gas: '15917702655',
  revert_reason: null,
  confirmation_duration: [0, 12000],
  type: 2,
  token_transfers_overflow: false,
  confirmations: 47513,
  position: 72,
  max_priority_fee_per_gas: '1267119384',
  transaction_tag: null,
  created_contract: null,
  value: '0',
  tx_types: ['contract_call'],
  from:
    {
      ens_domain_name: null,
      hash: '0xA3b711752f08980F4a71777217FA81304aEB8ee7',
      implementations: [],
      is_contract: false,
      is_scam: false,
      is_verified: false,
      metadata: null,
      name: null,
      private_tags: [],
      proxy_type: null,
      public_tags: [],
      watchlist_names: [],
    },
  gas_used: '55590',
  status: 'ok',
  to:
    {
      ens_domain_name: null,
      hash: '0x22C1f6050E56d2876009903609a2cC3fEf83B415',
      implementations: [[Object]],
      is_contract: true,
      is_scam: false,
      is_verified: true,
      metadata: { tags: [Array] },
      name: 'AdminUpgradeabilityProxy',
      private_tags: [],
      proxy_type: 'eip1967',
      public_tags: [],
      watchlist_names: [],
    },
  authorization_list: [],
  method: 'setApprovalForAll',
  fee: { type: 'actual', value: '747245415149790' },
  tx_tag: null,
  actions: [],
  gas_limit: '73310',
  gas_price: '13442083381',
  decoded_input:
    {
      method_call: 'setApprovalForAll(address to, bool approved)',
      method_id: 'a22cb465',
      parameters: [[Object], [Object]],
    },
  has_error_in_internal_txs: false,
  token_transfers: [],
  base_fee_per_gas: '12174963997',
  timestamp: '2024-12-08T17:44:23.000000Z',
  nonce: 464,
  block: 21359346,
  transaction_types: ['contract_call'],
  exchange_rate: '3859.75',
  block_number: 21359346,
  has_error_in_internal_transactions: false,
}

You can also go over the transaction visually at EVM Explorer transaction page.

Fetching Vitalik's Address Tokens

You can also query the blockchain address token balances as demonstrated on Stack Overflow. For example, let's query Vitalik's balances:

export type { AddressTokens } from "@evmexplorer/blockscout";
export { fetchTokensAddress } from "@evmexplorer/blockscout";

const data: AddressTokens = await fetchTokensAddress(
  '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
);
console.log(data.length)
console.log(data[0])

Address Tokens Output

6081
{
  token: {
    address: '0x28561B8A2360F463011c16b6Cc0B0cbEF8dbBcad',
    circulating_market_cap: '75858317.61202328',
    decimals: '9',
    exchange_rate: '0.00017784',
    holders: '14334',
    icon_url: 'https://assets.coingecko.com/coins/images/50348/small/1000000612.jpg?1727248974',
    name: 'MOO DENG',
    symbol: 'MOODENG',
    total_supply: '420690000000000000000',
    type: 'ERC-20',
    volume_24h: '10219755.637613483'
  },
  token_id: null,
  token_instance: null,
  value: '30000105889157756560'
}

Vitalik has 6081 tokens. The first token in the array of all 6081 tokens is Moo Deng token.

Fetching Latest Block Transactions

You can also query the latest block transactions with Ethers provider as demonstrated on Stack Overflow.

import { fetchBlockTransactionsBlockscout } from '@evmexplorer/blockscout';
const block = await provider.getBlock();
const data = await fetchBlockTransactionsBlockscout(block);

More information

EVM Explorer - Tracking Smart Contract Transaction Data

Blockscout - Ethereum API documentation

Blockscout - REST API Endpoints

Package Sidebar

Install

npm i @evmexplorer/blockscout

Weekly Downloads

31

Version

0.0.22

License

MIT

Unpacked Size

56.7 kB

Total Files

7

Last publish

Collaborators

  • pfedprog