0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

RPCエンドポイントを利用してウォレットを実装してみる #3特定トランザクションの情報表示

Posted at

テーマ設定

RPCエンドポイントを利用してウォレットのトランザクション表示機能を実装してみる。

前提環境

web3のインストール

npm install web3

実装

以下の内容でget_transaction.jsファイルを作成してください。

const { Web3 } = require('web3');

// RPCエンドポイントを設定
const web3 = new Web3('https://gateway-api.cabinet-node.com/{access_token}');

// 取得したいトランザクションハッシュを設定
const txHash = '0x83d9c6efacf9eb72645f2c65c8ed786925aceb5b8ea2a154b247d8c498a4fc59';

async function getTransactionByHash() {
   try {
       // トランザクションをトランザクションハッシュで取得
       const transaction = await web3.eth.getTransaction(txHash);
       
       if (transaction) {
           console.log('Transaction Details:', transaction);
       } else {
           console.log('No transaction found for this hash.');
       }
   } catch (error) {
       console.error('Error fetching transaction:', error);
   }
}

getTransactionByHash();

実行

node get_transaction.js

結果の例

Transaction Details: {
  blockHash: '0x54de2004be133565c0c6ee14b5daff080c07b027af2ef820ace86b44ed6a28e2',
  blockNumber: 20781385n,
  from: '0x4838b106fce9647bdf1e7877bf73ce8b0bad5f97',
  gas: 22111n,
  gasPrice: 14477399888n,
  maxFeePerGas: 14477399888n,
  maxPriorityFeePerGas: 0n,
  hash: '0x83d9c6efacf9eb72645f2c65c8ed786925aceb5b8ea2a154b247d8c498a4fc59',
  input: '0x',
  nonce: 695907n,
  to: '0x388c818ca8b9251b393131c08a736a67ccb19297',
  transactionIndex: 176n,
  value: 223512263928036655n,
  type: 2n,
  accessList: [],
  chainId: 1n,
  v: 0n,
  r: '0xa112d06391657c87e31f4bc5b87306df19909c0755aeb3a6dd6b6c798837ccbc',
  s: '0x5fc93f922e227978109ff75ae8f07d5a1049bd86b46273a734d81f56c4631df2',
  data: '0x'
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?