-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
web3 client not receiving eth_subscribe data from hardhat network #588
Comments
I have the same issue and I can confirm this. |
I think the Buidler EVM doesn't support websocket connections yet. You might get this to work if you use an in-process BEVM instead of connecting to |
|
As long as you don't start to override internal node objects I'm very pleased with your solution. ;) But it would be even more awesome If I can use your nice console.log plugin again which I currently can't with ganache. Any estimates on how long this could take? |
Do you know which kind of websocket messages does web3 expect? We may have already fixed this in #608 |
I don't know but maybe I can check out the 2.0 branch, if there's not too much migration to do. |
Dependening on the complexity of your setup, the only migration you might need to do is changing:
for
There are other breaking changes, but that's the one that almost everyone will run into. |
|
I'm on 1.99.0 now. Running a script says: npx buidler run scripts/deploy-gateway.js --network localhost
Compiling with 0.7.1
contracts/ConsumerExample.sol:19:58: Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
function onEthPriceFulfill(uint256[] memory ethPrices, uint256 requestId) public onlySelf {
^---------------^
Compiled 4 contracts successfully
TypeError: plugins_1.readArtifact is not a function
at getContractFactoryByName (/home/mkt/Projects/simplor/node_modules/@nomiclabs/buidler-ethers/src/helpers.ts:55:26)
at getContractFactory (/home/mkt/Projects/simplor/node_modules/@nomiclabs/buidler-ethers/src/helpers.ts:35:12)
at main (/home/mkt/Projects/simplor/scripts/deploy-gateway.js:3:46)
at Object.<anonymous> (/home/mkt/Projects/simplor/scripts/deploy-gateway.js:13:1)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12) 1.| async function main() {
2.| // We get the contract to deploy
3.| const SimplorGatewayFactory = await ethers.getContractFactory("SimplorGateway"); Are the changes documented somewhere in an easy to read form? |
You'll also need to install the new versions of the plugins. I can publish the relevant ones if you tell me which ones you are using in that project. |
I'm only using web3 and console.log. |
I just run @Detoo's reproduction against the 2.0 branch, and I'm afraid it's not fixed. |
Well... I will use ganache then but it would be really nice to have this fixed soon. I don't know if I have the time and motivation to take a closer look but I definitely think this should be fixed before 2.0 release anyway. Listening for contract events is at least half of all communication that is going on, I'd say. |
Is there any update on the status of this? I cannot listen to contract events. Major pain as it would be really useful to be able to use hardhat network evm for ALL localhost development instead of switching between ganache and hardhat for testing. |
@Thrasymachus01 it's definitely in our backlog, but we can't give an ETA for this right now. |
Is there an ETA on this one? I'm trying to replace all uses of |
Any updates on this? I feel like this is a pretty important feature to have. Have to use ganache if hardhat doesn't support websockets. |
Has this been resolved? I'm using a WSS connection to a forked BSC archive node but it's only compatible with ganache. when I try to fork with
I can't use HTTPS because the endpoint is broken:
It's super annoying cause this setup also breaks Hardhat's solidity I can't just use another node either, cause nobody seems to be hosting reasonably priced BSC archival nodes other than https://www.quicknode.com/ |
I don't think your comment is related to this issue, @EtDu. If you think you need to be able to fork a network using websocket, please open a separate issue. |
That doesn't mean that the endpoint is broken, it means that you are using a node that is not an archive node and you are forking from an old block number.
GetBlock added BSC archive nodes recently btw. Please use our discord server if you have more questions related to that, so we don't spam this issue. |
@fvictorio Thank you for the response, I'll open another issue for the WSS forking |
As @fvictorio mentions, another issue I created might be a duplicate of this one. Issue #1692 Here is the very small repo (1 tiny contract and 1 very small test file) to reproduce the issue: https://github.com/adamdry/ethers-event-issue For convenience, here is the smart contract: //SPDX-License-Identifier: UNLICENSED;
pragma solidity 0.8.4;
contract ContractA {
event TokensMinted(uint amount);
function mint(uint amount) public {
emit TokensMinted(amount);
}
} And this is my test code: import * as chai from 'chai'
import { BigNumber, ContractTransaction } from 'ethers'
import { ethers } from 'hardhat'
import { ContractA, ContractAFactory } from '../typechain'
const expect = chai.expect
describe("Example test", function () {
it("should fire the event", async function () {
const [owner] = await ethers.getSigners();
const contractAFactory = (await ethers.getContractFactory(
'ContractA',
owner,
)) as ContractAFactory
const contractA: ContractA = await contractAFactory.deploy()
contractA.on('TokensMinted', (amount: BigNumber) => {
// THIS LINE NEVER GETS HIT
console.log('###########')
})
const contractTx: ContractTransaction = await contractA.mint(123)
const contractReceipt: ContractReceipt = await contractTx.wait()
for (const event of contractReceipt.events!) {
console.log(JSON.stringify(event))
}
});
}); I was expecting the If I dig into the ContractReceipt the correct event data is there: {
"transactionIndex": 0,
"blockNumber": 2,
"transactionHash": "0x55d118548c8200e5e6c19759d9aab56cb2e6a274186a92643de776d617d51e1a",
"address": "0x5FbDB2315678afecb367f032d93F642f64180aa3",
"topics": [
"0x772f66a00a405709c30e7f18feadcc8f123b20c09c7260165d3eec36c9f21372"
],
"data": "0x000000000000000000000000000000000000000000000000000000000000007b",
"logIndex": 0,
"blockHash": "0x808e6949118509b5a9e482e84cf47921a2fcffbcd943ebbd8ce4f6671469ee01",
"args": [
{
"type": "BigNumber",
"hex": "0x7b"
}
],
"event": "TokensMinted",
"eventSignature": "TokensMinted(uint256)"
} Hopefully this can help with solving the issue. |
Confirming that eth_subscribe seems broken, simple block subscription does not work. I am spawning a vanilla hardhat node with Then I have an First issue: can't access signers, only HTTP(S) supported Second issue: accessing the provider via Third issue: even if I instantiate a websocket provider with my local node, I am not receiving events. it('works', async () => {
// const signer = (await ethers.getSigners())[0]
// console.log(signer.provider) // Throws with TypeError: OnlyHTTP(S) protocols are supported
const provider = new ethers.providers.WebSocketProvider('ws://localhost:8545')
const alice = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80', provider)
const nft = await new FodlNFTFactory(alice).deploy('tst', 'tst')
provider.on({}, (log, event) => {
console.log('heee')
console.log(log)
console.log(event)
})
provider.on('block', (block) => {
console.log('hooo')
console.log(block)
})
const tx = await nft.mint(alice.address, 1)
await tx.wait(1)
await tx.wait(1)
}) EDIT. Just out of curiosity I tried to put the hardhat node on automine + interval mining The it('works', async () => {
// const signer = (await ethers.getSigners())[0]
// console.log(signer.provider) // Throws with TypeError: OnlyHTTP(S) protocols are supported
const provider = new ethers.providers.WebSocketProvider('ws://localhost:8545')
const alice = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80', provider)
const nft = await new FodlNFTFactory(alice).deploy('tst', 'tst')
provider.on({}, (log, event) => {
console.log('heee')
console.log(log)
console.log(event)
})
provider.on('block', (block) => {
console.log('hooo')
console.log(block)
})
const tx = await nft.mint(alice.address, 1)
await tx.wait(10)
}) EDIT 2. Confirmed as people above that code is working well with |
#1692 may be a duplicate of this |
We released https://github.com/nomiclabs/hardhat/releases/tag/hardhat-core-v2.6.1 |
@fvictorio thanks for the update, unfortunately this hasn't fixed the issue for me. I'm still testing this as per the code in #1692 I do have some additional information: I tried rebooting my machine and trying again with no luck. I then downgraded back to Is there anything else I can do to try and help nail the problem down? |
I was going to complain about this same issue until I realized I was on hardhat@2.6.0 🤦 |
Hi, I am having a weird issue where my web3 client connecting to a local buidler-evm wasn't able to receive any event. I have a runnable example along with a control group here (https://github.com/Detoo/buidler-eth-subscribe-issue) but here's a quick summary of what I saw:
The code snippet
Expected Results
For sanity check, I tested the same codes with a ganache-cli evm instead and it did work:
Actual Results
However, when it run against a buidler-evm, I got nothing in response:
The evm logs show it did receive
eth_subscribe
:That led me to think maybe I did not setup buidler-evm properly but I not sure why. Any suggestion is very much appreciated, thanks!
The text was updated successfully, but these errors were encountered: