-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
eth_getLogs: invalid argument 0: hex number with leading zero digits #3379
Comments
Judging from the JSON-RPC Http package, I suspect there is a bug in web3.js when trying to fill the |
Thanks for opening this issue! We will check that closer asap. |
@nivida By the way, I used MetaMask as ethereum provider by |
I wasn't able to reproduce this using It does seem like an issue if you use a hex string as the argument to
In your wireshark output I see...
Are you setting that |
@cgewecke I didn't set the
I allocated some balance to this account
Reset the MetaMask to reset the account nounce.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test 1</title>
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
</head>
<body>
<button onclick="Deploy()">Deploy Contract</button>
<script>
const from = '0x2ecb718297080ff730269176e42c8278aa193434'; // This account is the one allocated in genesis.json
const web3 = new Web3(ethereum);
const bytecode = "6080604052348015600f57600080fd5b507f4be3cc765465b935ed0199e6e8b6be8003a65e3329002a60e7a817f3b734e88233604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390a1603f8060806000396000f3fe6080604052600080fdfea2646970667358221220fd91b74592ed3d345b06a1ca136ed6ed155ee97c1f8467ec97bdf78c4b91a8fd64736f6c63430006020033";
const abi = [
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "address",
"name": "owner",
"type": "address"
}
],
"name": "ConstructEvent",
"type": "event"
}
];
web3.eth.subscribe('logs', {}, function (error, result) {
if (!error)
console.log("result:", result);
else
console.log("err:", error);
});
function Deploy() {
let myContract = new web3.eth.Contract(abi);
myContract.deploy({
data: bytecode,
}).send({
from: from,
}).on('error', function (error) {
console.log("error:", error)
}).on('transactionHash', function (transactionHash) {
console.log("hash:", transactionHash);
}).on('receipt', function (receipt) {
console.log("receipt:", receipt)
});
}
</script>
</body>
</html> The smart contract is:
Compiled using Solidity 0.6.2 in Remix.
|
@Troublor Thanks for producing that example. Have a further simplified this case as a geth unit test PR #3394. It passes, successfully reporting an event from block number 5 on Travis here. (See logged output). The test is:
The test suggests the underlying issue may be with Metamask which implements it's own subscription strategy over HTTP using polling behind the scenes. Could you try running some version of the example in #3394 locally using just a node script or mocha test, connecting over websockets and seeing if that works? |
@cgewecke Indeed, the issue does not exist with websocket provider. Its seems like this is an issue in the provider offered by MetaMask. MetaMask doesn't support websocket provider yet. I might consider report this issue to MetaMask. Thanks for your effort. |
@Troublor Thanks for reporting and figuring this out! I'm sure other people will run into this as well. |
Expected behavior
Event listeners should work as expected
Actual behavior
Sometimes, especially when
eth.blockNumber < 0x10
, when an event is emitted in smart contract, error shows up on Geth console, sayingand the event listener does not work.
Steps to reproduce the behavior
web3.js
tries to get logs from blockchain withfromBlock < 0x10
Logs
JavaScript console from web3.js
no errors
Geth console
JSON-RPC Package using Wireshark
Versions
Web3.js:
1.2.6
, installed using Node.jsv8.17.0
with NPMv6.13.4
Geth:
1.9.10-stable
The text was updated successfully, but these errors were encountered: