When I try to get a transaction from a tx hash, it will sometimes return the correct result and sometimes return null. I can't see any pattern to its reaction.
Web3: 1.0.0-beta.34
Node: v9.6.1
This is copied directly from a Node REPL, note how I make the same call twice. The first time it returns correctly the second time it returns null.
bash-4.4# node
> const { abiDecoder, getTransaction, getBlock } = require('./config/web3')
undefined
> getTransaction('0xda23e74c898c009968c8fe2217958c94fdbb2642c8fb5c0e210a76dd907f0cac').then(console.log)
Promise {
<pending>,
domain:
Domain {
domain: null,
_events:
{ removeListener: [Function: updateExceptionCapture],
newListener: [Function: updateExceptionCapture],
error: [Function: debugDomainError] },
_eventsCount: 3,
_maxListeners: undefined,
members: [] } }
> { blockHash: '0x434418a5c80e3a6230e37accfd4993e049a0bfc28e11ba793359a2ceec99c914',
blockNumber: 3316932,
from: '0x60AdC0F89a41AF237ce73554EDe170D733ec14E0',
gas: 564994,
gasPrice: '1000000000',
hash: '0xda23e74c898c009968c8fe2217958c94fdbb2642c8fb5c0e210a76dd907f0cac',
input: '0x24df90ab00000000000000000000000000000000000000000000000000000000000000190000000000000000000000006ea64ae4c9bcb1998b96732f475067998705d85e000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000002386f26fc0ffff000000000000000000000000627306090abab3a6e1400e9345bc60c78a8bef57000000000000000000000000000000000000000000000000000000000000000a6d6174742d7374616b6500000000000000000000000000000000000000000000',
nonce: 19,
to: '0xCaC53a387D8E38C10A6A077482bd1741340e4e6E',
transactionIndex: 5,
value: '0',
v: '0x2a',
r: '0x7a1ea5844fe6398566524fb0b301f10fda65c0e2647df0da45e252f940848b87',
s: '0x3c04673c5094d2ebd4087b3ca877164f549c8eeeb0cfbbb91f2d99c11751633e' }
> getTransaction('0xda23e74c898c009968c8fe2217958c94fdbb2642c8fb5c0e210a76dd907f0cac').then(console.log)
Promise {
<pending>,
domain:
Domain {
domain: null,
_events:
{ removeListener: [Function: updateExceptionCapture],
newListener: [Function: updateExceptionCapture],
error: [Function: debugDomainError] },
_eventsCount: 3,
_maxListeners: undefined,
members: [] } }
> null
As an aside, this exact code was running fine a week ago. I've reverted to an old version of my project that I know was running correctly and even that version seems to be having issues.
I came up with a short snippet of code that showcases the behavior:
const Web3 = require('web3')
const web3 = new Web3('https://ropsten.infura.io/');
const abi = JSON.parse('[{"constant":true,"inputs":[],"name":"masterCopy","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"stakes","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_masterCopy","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_stakeId","type":"uint256"},{"indexed":false,"name":"_contractAddress","type":"address"}],"name":"StakeCreated","type":"event"},{"constant":false,"inputs":[{"name":"_value","type":"uint256"},{"name":"_token","type":"address"},{"name":"_minimumFee","type":"uint256"},{"name":"_data","type":"string"},{"name":"_stakeReleaseTime","type":"uint256"},{"name":"_arbiter","type":"address"}],"name":"createDelphiStake","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getNumStakes","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}]')
const DelphiStakeFactory = new web3.eth.Contract(abi, '0xcac53a387d8e38c10a6a077482bd1741340e4e6e');
async function handler() {
let factoryEvents = await DelphiStakeFactory.getPastEvents({fromBlock: 0, toBlock: 'latest'});
for (let event of factoryEvents) {
const rawTransaction = await web3.eth.getTransaction(event.transactionHash);
console.log(event.blockNumber, rawTransaction == null)
}
}
handler();
It ended up being an issue with Infura's ropsten network.
@c-o-l-o-r I'm seeing this issue with Infura Ropsten as well. How did you get around this issue?
@ztnark there is likely an issue on Infura's side with the node you are connecting to. I got around the issue by waiting a couple hours until things were operating normal again.
Thank you. It also seems that waiting for additional confirmations helped the issue.
let Web3 = require('web3');
let fs = require('fs');
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
};
exports.getMessage = function(hash) {
var transaction = web3.eth.getTransaction(hash);
console.log('get transaction from hash :'+ JSON.stringify(transaction));
};
return transaction涓簄ull锛宑an you help me to solve the problems
Most helpful comment
Thank you. It also seems that waiting for additional confirmations helped the issue.