18 votes
Accepted

Better pattern to detect web3 default account when using metamask

The one method that is more reliable than the in-page accounts array is web3.eth.getAccounts(accounts => console.log(accounts[0])). This will asynchronously request the accounts array, and call ...
user avatar
  • 2,602
14 votes
Accepted

Connecting to hosted web3 provider from NodeJS backend

I've replaced const web3 = new Web3(new Web3.providers.HttpProvider("http://rpc.ethapi.org:8545")); with: const web3 = new Web3(new Web3.providers.HttpProvider("https://ropsten.infura.io/TOKEN")); ...
user avatar
  • 4,168
14 votes
Accepted

Infura web3 provider for Events (.get & .watch)

Infura currently doesn't support WebSockets (required for events using Web3 v1, otherwise you get the error "The current provider doesn't support subscriptions" when using infura as HttpProvider), so ...
user avatar
  • 4,785
12 votes

Infura web3 provider for Events (.get & .watch)

I have been using Infura with web3 1.0 in mainnet. Here is my code, hope it helps var Web3 = require('web3') var request = require('request'); var contract = require('truffle-contract') var ...
user avatar
  • 1,127
11 votes
Accepted

How does Truffle work without a web3 provider?

In Truffle 0.2.x or 0.3.x with the truffle-default-builder, app.js in the ./build folder will include considerable bootstrap code that sets the stage. This is why the HTML should link to the ./build ...
user avatar
  • 51.8k
10 votes

Injecting a private key into web3.js execution context

Using web3js 1.0.0: const privateKey = 'e0f34403.................................29c8c861937'; const account = web3.eth.accounts.privateKeyToAccount('0x' + privateKey); web3.eth.accounts.wallet.add(...
user avatar
10 votes

Better pattern to detect web3 default account when using metamask

Here's what I use in my Dapp. It seems to work pretty well. function getWeb3(callback) { if (typeof window.web3 === 'undefined') { // no web3, use fallback console.error("Please use a web3 ...
user avatar
  • 2,277
7 votes
Accepted

Binance Smart Chain RPC Rate Limit

Since these are public endpoints, they are probably monitoring your usage by your IP address. So you can only do 10K requests/5min from your IP. It doesn't matter if you have more applications or ...
user avatar
  • 749
6 votes

Better pattern to detect web3 default account when using metamask

Checking web3.eth.accounts[0] every 100 milliseconds is way faster in some cases than web3.eth.getAccounts(): // Option 1: web3.eth.getAccounts(console.log); // Option 2: (function loop() { if (...
user avatar
  • 163
6 votes

What are providers in the Ethereum?

https://api.myetherapi.com/eth is a provider. Web3 provider is a website running geth or parity node which talks to Ethereum network.
user avatar
6 votes

How to connect truffle using HDWallet provider to Websocket-powered node?

You can pass an instance of the provider instead of a string as a second argument. So you can pass a websocket provider in: const webSocketProvider = new Web3.providers.WebsocketProvider(...); const ...
user avatar
  • 163
6 votes
Accepted

get address of new contract from contract factory

The response you are getting is the receipt of the transaction. Return values from functions which create transactions, to my knowledge, can only be true or false. However, you should be able to ...
user avatar
6 votes
Accepted

building your own web3 provider

You are asking about very niche and complex problem, so one cannot expect ready made tutorials to be available. I would suggest Reverse engineering web3.js Reverse engineering MetaMask Reverse ...
user avatar
5 votes

Check if web3js is connected to node

Try this, it also reconnects to the node. Using web3js@1.0 beta web3.eth.net.isListening().then((s) => { console.log('We\'re still connected to the node'); }).catch((e) => { console.log(...
user avatar
  • 51
5 votes

What are providers in the Ethereum?

A provider links to a running node. For instance parity or geth. A node has the ability to view and interact with the blockchain.
user avatar
  • 1,181
5 votes
Accepted

What are the web3 httpProvider options?

If I were to deploy this code on a website, what would I set this variable to, and how does that work? You can replace it with your own working node or you can use some service like infura.io which ...
user avatar
  • 3,027
5 votes
Accepted

Unable to detect MetaMask in browser

What metamask do is inject javascript into the document when you access it. The browser will execute this javascript, and is that execution that will define de variable web3. But when you are ...
user avatar
  • 828
5 votes

difference between metamask and ethereum provider

Yes, Metamask uses Infura in the background to connect to the network. So Metamask is a user interface on top of Infura service. However, nothing forces you to use Metamask, it just happens to be ...
user avatar
4 votes

Better pattern to detect web3 default account when using metamask

A couple things I've noticed from using MetaMask. defaultAccount isn't always populated. It's safer to use web3.eth.accounts[0] as your check to see whether or not an account is selected. You'll ...
user avatar
  • 1,128
4 votes
Accepted

Getting data from contract to the DApp without provider

You can run the ethereum node on a dedicated server as you mentioned but rather than opening port 8545 and talk to it directly, Create a nodeJS API server on that instance(which will use web3.js) and ...
user avatar
  • 3,322
4 votes
Accepted

possible reason for insufficient funds for gas * price + value

So... I figured out. The reason is Web3 takes the private key in 0xa0b1c2... format. I used to use ethereumjs-tx package, which takes a private key in const privateKey = new Buffer('a0b1c2...') ...
user avatar
  • 245
4 votes
Accepted

Uncaught ReferenceError: Web3 is not defined Solidity

I hope you are using web3 as browser module. As in their documentation, you can add the CDN link using <script> tags as below, <script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/...
user avatar
4 votes

What are the Node Providers for Avalanche Network

I recommend Chainstack. Easy to set up, fast nodes and great support! Create an account on Chainstack How to deploy a node on Chainstack They also have a page in the docs with a lot of JSON-RPC API ...
user avatar
  • 366
3 votes

Connecting to hosted web3 provider from NodeJS backend

You should be careful using Infura because it can relay you incorrect information. Infura is architected with multiple nodes behind a load balancer. All of these nodes are not in sync, so you can ...
user avatar
  • 359
3 votes

socket.timeout timed out when connecting to a remote server with web3.py

First double check that IP addresses are correct in your scripts. Then use telnet command to ensure that you can connect to RPC port from the client computer: telnet 163.xxx.xxx.xxx 8545 You ...
user avatar
3 votes

web3.eth.personal : "Method not found"

For parity : As documented in the options, available under parity --help not all API’s are exposed by default. However you can simply enable them by running parity with the flag: --jsonrpc-apis APIS ...
user avatar
  • 17.6k
3 votes

GUI does not work for contract

I don't have 50 reputation to ask a comment question, but I'm assuming the issue you're running into is because your setters need to be promises and require a .then(function(response, error) {}) chain....
user avatar
  • 51
3 votes
Accepted

How can I increase EVM time in web3.py?

OK, this seems to to the job: web3 = Web3(HTTPProvider("http://127.0.0.1:8545")) provider = web3.providers[0] provider.make_request("evm_increaseTime", [numOfSeconds])
user avatar
3 votes
Accepted

How to configure truffle network with IPC provider?

According to https://truffleframework.com/docs/truffle/reference/configuration there is a field called provider. Using this field an arbitrary web3 connection provider can be injected. For IPC on ...
user avatar
  • 7,194
3 votes

web3-react does not appear to be exposing Ethers.js instance

In fact with web3-react: const provider = new providers.Web3Provider(library.provider); is equal to: const context = useWeb3React(); const { library } = context; Then you can do everything that ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible