Transactions
使用 web3.js 迭代私有區塊鏈中的交易
這個問題與這個問題類似。我正在嘗試遍歷私有區塊鏈中的所有交易,並查找在每個交易的“數據”欄位中發送的特定數據。以下方法是否有效:
// Fetch all transaction logs with the specified address filter = web3.eth.filter({fromBlock: 0, toBlock: 'latest', address: to_addr}); // Get all entries results = filter.get((function(error, result){ if (!error) console.log("[I] Fetched all transactions sent or sent to " + to_addr); else console.log("[E] An error has occurred " + error); }); var json_tuple; // Iterate through the transactions in the logs for(var log in results) { var log_tx_hash = log.transactionHash; // Lookup transaction with hash var tx = web3.eth.getTransaction(log_tx_hash); // Check the to and from addresses. We skip transactions unrelated to the current sender if(tx.from === from_addr) { // Parse transaction data and check recipient json_tuple = JSON.parse(tx.input); if(field in json_tuple) { //Do something with a field of the input data sent // as a JSON object console.log("We have found a transaction with data: " + json_tuple[[field]]); } } }
這是基於收件人地址過濾器迭代交易的正確方法嗎?
這是一個腳本來查找到/從一個帳戶的交易。您可以從所有交易中提取數據,即
input
欄位。有關的: