3. Viewing account and transaction information using Web3 Data API

์ด์ „ ํŠœํ† ๋ฆฌ์–ผ์„ ํ†ตํ•ด ์Šค๋งˆํŠธ ์ปจํŠธ๋ž™ํŠธ๊ฐ€ ๋ฌด์—‡์ธ์ง€ ๋ฐฐ์šฐ๊ณ  ์ง์ ‘ ์ด๋”๋ฆฌ์›€ Holesky์—์„œ ํŠธ๋žœ์žญ์…˜์„ ์‹คํ–‰ํ•ด ์Šค๋งˆํŠธ ์ปจํŠธ๋ž™ํŠธ๋ฅผ ๋ฐฐํฌํ•˜๊ณ  ํ˜ธ์ถœํ•ด ๋ณด์•˜์Šต๋‹ˆ๋‹ค. ์ด๋ฒˆ ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” Nodit Web3 Data API๋ฅผ ์ด์šฉํ•ด ๋ฐฐํฌ๋ฅผ ์œ„ํ•ด ์‹คํ–‰ํ•œ ํŠธ๋žœ์žญ์…˜์˜ ์ •๋ณด์™€ ์Šค๋งˆํŠธ ์ปจํŠธ๋ž™ํŠธ๋ฅผ ๋ฐฐํฌํ•œ ๊ณ„์ •์˜ ํŠธ๋žœ์žญ์…˜ ์ •๋ณด๋ฅผ ํ™•์ธํ•ด ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

๐Ÿ“˜

์ด๋ฒˆ ํŠœํ† ๋ฆฌ์–ผ์„ ์ง„ํ–‰ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” Nodit API Key๊ฐ€ ํ•„์š”ํ•ด์š”!

Nodit API Key๋Š” Nodit ์ฝ˜์†”์— ํšŒ์›๊ฐ€์ž…ํ•˜์—ฌ ํš๋“ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜ ๋งํฌ๋ฅผ ํด๋ฆญํ•˜์—ฌ Nodit ์ฝ˜์†”์— ํšŒ์›๊ฐ€์ž…ํ•˜๊ณ  ๋‹ค์–‘ํ•œ ๋ธ”๋ก์ฒด์ธ ๋…ธ๋“œ๋ฅผ ์ด์šฉํ•ด ๋ณด์„ธ์š”!


ํŠธ๋žœ์žญ์…˜ ์กฐํšŒ

ํŠธ๋žœ์žญ์…˜์„ ํ†ตํ•ด setMessage ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ํ–ˆ์„ ๋•Œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํŠธ๋žœ์žญ์…˜ ์ •๋ณด๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

{
  type: 2,
  chainId: 17000,
  nonce: 13,
  maxPriorityFeePerGas: BigNumber { _hex: '0x59682f00', _isBigNumber: true },
  maxFeePerGas: BigNumber { _hex: '0x59682f0e', _isBigNumber: true },
  gasPrice: null,
  gasLimit: BigNumber { _hex: '0x01303d', _isBigNumber: true },
  to: '0x4c12Da0413EA27D6Fe3957955940FFBA949C4cdB',
  value: BigNumber { _hex: '0x00', _isBigNumber: true },
  data: '0x368b87720000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003c4e6f646974206973206f6e65206f66207468652062657374204e6f64652050726f7669646572205365727669636520696e2074686520776f726c642100000000',
  accessList: [],
  hash: '0xd58046b4ca4558b90312b83b8e1f8bd1dbea870be516239855b93141463dafba',
  v: 0,
  r: '0xb38d85427e3c4558bbc8cb27b095d57ee828b80fa3345d78d6a1d864f40405f4',
  s: '0x43916907718ca24ed6474a7382f383ba338955c754437db2d6985a6a76635c4b',
  from: '0xEc801CFCF110675F32b593A7f25d09B8f7c6D291',
  confirmations: 0,
  wait: [Function (anonymous)]
}

์ด๋Ÿฌํ•œ ํŠธ๋žœ์žญ์…˜ ์ •๋ณด๋ฅผ Nodit Web3 Data API๋ฅผ ์ด์šฉํ•ด์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Nodit Web3 Data API ์ค‘ Get Transaction By Hash API๋ฅผ ์ด์šฉํ•ด ๋™์ผํ•œ ํŠธ๋žœ์žญ์…˜ ์ •๋ณด๋ฅผ ํ™•์ธํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ํ™˜๊ฒฝ์—์„œ ๊ฐ„ํŽธํ•˜๊ฒŒ HTTP ์š”์ฒญ์„ ์ „์†กํ•˜๊ธฐ ์œ„ํ•ด axios๋ผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

$ npm install axios

axios๋ฅผ ์„ค์น˜ํ•œ ํ›„ axios ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•ด Nodit Web3 Data API๋ฅผ ํ˜ธ์ถœํ•ฉ๋‹ˆ๋‹ค. aixos ์ธ์Šคํ„ด์Šค์˜ ๊ฒฝ์šฐ, baseURL๊ณผ headers๋ฅผ ๋ฏธ๋ฆฌ ์„ค์ •ํ•˜์—ฌ ํŽธ๋ฆฌํ•˜๊ฒŒ HTTP ์š”์ฒญ์„ ์ „์†กํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค.

// axiosRequest.ts

import axios from "axios";

const noditAPIKey = "your_nodit_api_key";
const axiosInstance = axios.create({
  baseURL: "https://web3.nodit.io/v1/ethereum/holesky",
  headers: {
    "Content-Type": "application/json",
    Accept: "application/json",
    "X-API-KEY": noditAPIKey,
  },
});

๊ทธ๋ฆฌ๊ณ  ์ฆ‰์‹œ์‹คํ–‰ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด axios ์ธ์Šคํ„ด์Šค๊ฐ€ Get Transaction By Hash API๋ฅผ ์‹คํ–‰ํ•˜๋Š” ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค. Get Transaction By Hash API๋Š” ํŠธ๋žœ์žญ์…˜ ํ•ด์‹œ๋ฅผ ํ•„์ˆ˜ Body Params๋กœ ๋ฐ›์Šต๋‹ˆ๋‹ค. withDecode๋ฅผ true๋กœ ์„ค์ •ํ•  ๊ฒฝ์šฐ ํ•ด๋‹น ํŠธ๋žœ์žญ์…˜์˜ Data ํ•„๋“œ์— ์ž…๋ ฅ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ๋””์ฝ”๋”ฉ ๋œ ๊ฐ’์œผ๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

(async () => {
  try {
    const txResult = await axiosInstance.post(
      "/blockchain/getTransactionByHash",
      {
        transactionHash:
          "0xd58046b4ca4558b90312b83b8e1f8bd1dbea870be516239855b93141463dafba",
        withDecode: true,
      }
    );
    console.log(txResult.data);
    console.log(txResult.data.decodedInput.args[0]);
  } catch (error) {
    console.error(error);
  }
})();


์ „์ฒด ์ฝ”๋“œ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค. ํŒŒ์ผ์„ ์‹คํ–‰ํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•ด ๋ณด์„ธ์š”!

// axiosRequest.ts

import axios from "axios";

const noditAPIKey = "your_nodit_api_key";
const axiosInstance = axios.create({
  baseURL: "https://web3.nodit.io/v1/ethereum/holesky",
  headers: {
    "Content-Type": "application/json",
    Accept: "application/json",
    "X-API-KEY": noditAPIKey,
  },
});

(async () => {
  try {
    const txResult = await axiosInstance.post(
      "/blockchain/getTransactionByHash",
      {
        transactionHash:
          "0xd58046b4ca4558b90312b83b8e1f8bd1dbea870be516239855b93141463dafba",
        withDecode: true,
      }
    );
    console.log(txResult.data);
    console.log(txResult.data.decodedInput.args[0]);
  } catch (error) {
    console.error(error);
  }
})();


์•„๋ž˜์™€ ๊ฐ™์ด ํŠธ๋žœ์žญ์…˜์˜ ์ •๋ณด์™€ ๋””์ฝ”๋”ฉ ๋œ ํŠธ๋žœ์žญ์…˜์˜ Data ํ•„๋“œ์˜ ๊ฐ’์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

{
  transactionHash: '0xd58046b4ca4558b90312b83b8e1f8bd1dbea870be516239855b93141463dafba',
  transactionIndex: '4',
  blockHash: '0x2710f36851312fbe2a20c8afd04b1f34b135e1cf59b0bf8881ee8fc1f91da5b0',
  blockNumber: '2319452',
  from: '0xEc801CFCF110675F32b593A7f25d09B8f7c6D291',
  to: '0x4c12Da0413EA27D6Fe3957955940FFBA949C4cdB',
  value: '0',
  input: '0x368b87720000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003c4e6f646974206973206f6e65206f66207468652062657374204e6f64652050726f7669646572205365727669636520696e2074686520776f726c642100000000',
  functionSelector: '0x368b8772',
  decodedInput: {
    type: 'function',
    name: 'setMessage',
    signature: 'setMessage(string)',
    args: [ [Object] ]
  },
  nonce: '13',
  gas: '77885',
  gasPrice: '1500000007',
  maxFeePerGas: '1500000014',
  maxPriorityFeePerGas: '1500000000',
  gasUsed: '76997',
  cumulativeGasUsed: '726811',
  effectiveGasPrice: '1500000007',
  contractAddress: null,
  type: '2',
  status: '1',
  logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
  accessList: [],
  timestamp: 1726125228
}

// console.log(txResult.data.decodedInput.args[0]);
{
  name: 'message',
  type: 'string',
  value: 'Nodit is one of the best Node Provider Service in the world!'
}

๐Ÿ“˜

์ด๋”๋ฆฌ์›€ Explorer์—์„œ๋Š” ํŠธ๋žœ์žญ์…˜์ด ํ™•์ธ๋˜๋Š”๋ฐ Web3 Data API๋กœ๋Š” ๊ฒฐ๊ณผ๊ฐ€ ๋ฐ˜ํ™˜๋˜์ง€ ์•Š์•„์š”.

Web3 Data API์˜ ๊ฒฝ์šฐ, ๋ฐ์ดํ„ฐ ๋ฌด๊ฒฐ์„ฑ์„ ํ™•๋ณดํ•˜๊ธฐ ์œ„ํ•ด 6๋ธ”๋ก์ด ์ง€๋‚˜ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š์„ ๋ฐ์ดํ„ฐ๋ฅผ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์„ ์ •์ฑ…์œผ๋กœ ํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋ธ”๋ก์ด ์ƒ์„ฑ๋œ ์งํ›„ API๋กœ ์กฐํšŒํ•  ๊ฒฝ์šฐ ์‘๋‹ต์ด ๋ฐ˜ํ™˜๋˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์œผ๋ฉฐ ์ฆ‰์‹œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜ํ™˜๋ฐ›๊ณ  ์‹ถ๋‹ค๋ฉด Node API์˜ eth_getTransactionByHash API๋ฅผ ์ด์šฉํ•ด ๋ณด์„ธ์š”!


๊ณ„์ •์„ ์ด์šฉํ•œ ํŠธ๋žœ์žญ์…˜ ์กฐํšŒ

์ด๋ฒˆ์—๋Š” ๊ณ„์ •์„ ์ด์šฉํ•ด ํ•ด๋‹น ๊ณ„์ •์ด ์‹คํ–‰ํ•œ ํŠธ๋žœ์žญ์…˜์„ ์กฐํšŒํ•ด ๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. Nodit์˜ Web3 Data API ์ค‘ Get Transactions By Account API๋ฅผ ์ด์šฉํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰์‹œ์‹คํ–‰ํ•จ์ˆ˜์˜ ๋‚ด์šฉ์„ ์•„๋ž˜์™€ ๊ฐ™์ด ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

import axios from "axios";

const noditAPIKey = "your_nodit_api_key";
const axiosInstance = axios.create({
  baseURL: "https://web3.nodit.io/v1/ethereum/holesky",
  headers: {
    "Content-Type": "application/json",
    Accept: "application/json",
    "X-API-KEY": noditAPIKey,
  },
});

(async () => {
  try {
    const txResult = await axiosInstance.post(
      "/blockchain/getTransactionsByAccount",
      {
        accountAddress: "0xEc801CFCF110675F32b593A7f25d09B8f7c6D291",
        withDecode: true,
      }
    );
    for (const item of txResult.data.items) {
      console.log(item);
    }
  } catch (error) {
    console.error(error);
  }
})();

Get Transactions By Account API๋Š” accountAddress๋ฅผ ์ธ์ž๋กœ ๋ฐ›์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  withDecode๋ฅผ true๋กœ ํ•˜์—ฌ ๋””์ฝ”๋”ฉ ๋œ ํŠธ๋žœ์žญ์…˜์˜ Data ํ•„๋“œ์˜ ๊ฐ’์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. ์‹คํ–‰ํ•˜๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ฒฐ๊ณผ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

{
  transactionHash: '0x269382830d9910b6c80399ef3af87b6217a41caee24a0d3c24e32d72cc56f866',
  transactionIndex: '2',
  blockHash: '0x2c1c0196f4ae18a7bd48e4c5c4e3328b8026f947839f3b92e137504122463a61',
  blockNumber: '2320187',
  from: '0xEc801CFCF110675F32b593A7f25d09B8f7c6D291',
  to: '0x4c12Da0413EA27D6Fe3957955940FFBA949C4cdB',
  value: '0',
  input: '0x368b87720000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003d4e6f646974206973206f6e65206f66207468652062657374204e6f64652050726f7669646572205365727669636520696e2074686520776f726c642121000000',
  functionSelector: '0x368b8772',
  decodedInput: {
    type: 'function',
    name: 'setMessage',
    signature: 'setMessage(string)',
    args: [ [Object] ]
  },
  nonce: '15',
  gas: '46015',
  gasPrice: '1500000007',
  maxFeePerGas: '1500000014',
  maxPriorityFeePerGas: '1500000000',
  gasUsed: '41100',
  cumulativeGasUsed: '526530',
  effectiveGasPrice: '1500000007',
  contractAddress: null,
  type: '2',
  status: '1',
  logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
  accessList: [],
  timestamp: 1726134900
},
{
  transactionHash: '0x80846b0c169656f1bcb390b1286205f792d0ee9a456d320a7703ca8e168225e2',
  transactionIndex: '1',
  blockHash: '0x914d95b6ca009d9b198cd15beb0e279652fd38cc93ef8925ecbbff7320524087',
  blockNumber: '2318601',
  from: '0xEc801CFCF110675F32b593A7f25d09B8f7c6D291',
  to: '0x4c12Da0413EA27D6Fe3957955940FFBA949C4cdB',
  value: '0',
  input: '0x368b87720000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f49742069732061206d6573736167650000000000000000000000000000000000',
  functionSelector: '0x368b8772',
  decodedInput: {
    type: 'function',
    name: 'setMessage',
    signature: 'setMessage(string)',
    args: [ [Object] ]
  },
  nonce: '4',
  gas: '31821',
  gasPrice: '1500000007',
  maxFeePerGas: '1500000014',
  maxPriorityFeePerGas: '1500000000',
  gasUsed: '31468',
  cumulativeGasUsed: '52468',
  effectiveGasPrice: '1500000007',
  contractAddress: null,
  type: '2',
  status: '1',
  logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
  accessList: [],
  timestamp: 1726114152
},
...
{
  transactionHash: '0x65fdeee8c624704070317475543d6b8a59ed0a157e925bc887cd1cb8a6d04470',
  transactionIndex: '5',
  blockHash: '0x2875c6a946e6b95d21370595739d921a07af4154c74d7f804ea1a6e535506f9d',
  blockNumber: '2312751',
  from: '0x007aB5199B6c57F7aA51bc3D0604a43505501a0C',
  to: '0xEc801CFCF110675F32b593A7f25d09B8f7c6D291',
  value: '10000000000000000',
  input: '0x',
  functionSelector: '0x',
  nonce: '88109',
  gas: '21000',
  gasPrice: '1500000007',
  maxFeePerGas: '1500000014',
  maxPriorityFeePerGas: '1500000000',
  gasUsed: '21000',
  cumulativeGasUsed: '753089',
  effectiveGasPrice: '1500000007',
  contractAddress: null,
  type: '2',
  status: '1',
  logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
  accessList: [],
  timestamp: 1726036116
}

Nodit์€ ๊ณ„์ •์ด ์‹คํ–‰ํ•œ ํŠธ๋žœ์žญ์…˜ ์ •๋ณด ํ™•์ธ ์™ธ์—๋„ Internal ํŠธ๋žœ์žญ์…˜, ๊ณ„์ •์˜ ๋‹ค์Œ Nonce ํ™•์ธ ๋“ฑ ๊ณ„์ •๊ณผ ๊ด€๋ จ๋œ ๋‹ค์–‘ํ•œ API๋ฅผ ์ œ๊ณตํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜ ๋งํฌ๋ฅผ ํด๋ฆญํ•ด Nodit์ด ์ œ๊ณตํ•˜๋Š” ๋‹ค์–‘ํ•œ API๋ฅผ ํ™•์ธํ•ด ๋ณด์„ธ์š”!

Nodit Web3 Data API ๋ฐ”๋กœ๊ฐ€๊ธฐ