admin管理员组文章数量:1305230
I have problem in Web3 provider recently. I have used HttpProvider as Web3 Provider, but now I cannot use it. Previous projects are also not executed. Here is my code and Error:
Code:
const url = `/{my_api_key}`;
const web3 = new Web3(new Web3.providers.HttpProvider(url));
Error Message:
const web3 = new Web3(new Web3.providers.HttpProvider(url));
^TypeError: Web3.providers.HttpProvider is not a constructor.
...
How can I fix it?
So I have tried to fix this error by controlling Web3 Version, changing providers, etc, but not fixed.
I have problem in Web3 provider recently. I have used HttpProvider as Web3 Provider, but now I cannot use it. Previous projects are also not executed. Here is my code and Error:
Code:
const url = `https://sepolia.infura.io/v3/{my_api_key}`;
const web3 = new Web3(new Web3.providers.HttpProvider(url));
Error Message:
const web3 = new Web3(new Web3.providers.HttpProvider(url));
^TypeError: Web3.providers.HttpProvider is not a constructor.
...
How can I fix it?
So I have tried to fix this error by controlling Web3 Version, changing providers, etc, but not fixed.
Share Improve this question edited Jul 18, 2023 at 15:48 TylerH 21.1k77 gold badges79 silver badges112 bronze badges asked Jul 18, 2023 at 15:35 AresColinAresColin 191 silver badge3 bronze badges 1-
1
If the url you have provided is the url you are using, you are missing a $ for the interpolation to work. It should be
https://sepolia.infura.io/v3/${my_api_key}
; – Phobos Commented Jul 18, 2023 at 15:56
3 Answers
Reset to default 8For me, wrapping works
replace const Web3 = require('web3)
with const {Web3} = require('web3')
Try to install web3 version 1.10.0
npm uninstall web3
then
npm i [email protected]
Install the latest web3 library version by :
npm i web3@latest
then add in your code :
const express = require('express');
const {Web3} = require('web3');
本文标签: javascriptHow to fix error Web3providersHttpProvider is not a constructorStack Overflow
版权声明:本文标题:javascript - How to fix error: Web3.providers.HttpProvider is not a constructor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741799013a2398110.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论