klaytn / caver-js

Official caver-js repository
GNU Lesser General Public License v3.0
114 stars 75 forks source link

Event subscription as the first request results in fromBlock parameter to be deleted #570

Closed jyeoniii closed 2 years ago

jyeoniii commented 2 years ago

Describe the bug Race condition arises when the first request made by a Websocket provider is a subscription to an event which includes a request for historical logs. It's been fixed in web3.js but it seems that the same bug still exists in caver-js.

How to reproduce Create Caver using WebsocketProvider and request event subscription for the first request.

const caver = new Caver('wss://api.baobab.klaytn.net:8652');
const contract = new caver.klay.Contract(abi, contractAddress);
contract.events.allEvents({ fromBlock: 0 }).on('data', console.log);

If I call something like await caver.klay.getAccounts() before the subscription, it works fine.

Expected behavior All events of the contract from block 0 should be retrieved.

Environment (please complete the following information)

jimni1222 commented 2 years ago

@jyeoniii Thank you for reporting. You can use caver-js v1.6.7-rc.1 :)