17 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 ...
DanF's user avatar
  • 2,616
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")); ...
manidos's user avatar
  • 4,278
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 ...
Miguel Mota's user avatar
  • 5,103
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 ...
maheshmurthy's user avatar
  • 1,227
11 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(...
Gediminas Rimsa's user avatar
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 ...
Rob Hitchens's user avatar
  • 54.8k
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 ...
0xcaff's user avatar
  • 2,447
8 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 ...
Filip's user avatar
  • 931
7 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 ...
Mitar's user avatar
  • 173
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 (...
traxium's 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.
Usama Ahmed's user avatar
6 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.
Victory's user avatar
  • 1,231
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 ...
Zack McGinnis's 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 ...
Mikko Ohtamaa's user avatar
5 votes
Accepted

Check if web3js is connected to node

Try this, it also reconnects to the node. Using [email protected] beta web3.eth.net.isListening().then((s) => { console.log('We\'re still connected to the node'); }).catch((e) => { console.log(...
Mike's user avatar
  • 66
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 ...
Roman Frolov's user avatar
  • 3,167
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 ...
bordalix's user avatar
  • 898
5 votes
Accepted

How can I tell if a node I am using is a full archive node?

A full archive node has access to the historical state of the blockchain. For example, if the node returns balance of an account (which has some eth) at block 1 then that node will be an archive node. ...
Ankit Chiplunkar's user avatar
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 ...
Lauri Peltonen's user avatar
5 votes
Accepted

How to authenticate with an Ethereum account through personalSign?

It's personal_sign now, not eth_personalSign. It has always been personal_sign, it's probably just a typo in the Metamask docs. const message = "Hello from Ethereum Stack Exchange!"; const ...
q9f's user avatar
  • 32.8k
5 votes

Do we need to use both Metamask and Alchemy as providers?

As far as my understanding goes, you would end up using a fast connection provider, such as Alchemy when reading all the necessary info from your dapp. You won't get any accounts from Alchemy, since ...
phaze's user avatar
  • 1,555
5 votes

Have any a16z-backed protocols ever been hacked?

DefiLlama maintains a database of a large number of capital raises (including the amount raised and VC investors) and hackes/exploits. If you merge these two databases by company name and filter by ...
Markus Schick's 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 ...
DeviateFish's 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 ...
Sanchit's user avatar
  • 3,472
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...') ...
Bigman's 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/...
Achala Dissanayake's 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 ...
Dave Dev Advocate Chainstack's user avatar
4 votes

Faced a problem whiling getting Ethereum transactions which are in mempool

You can get the pending transactions using Chainstack's WSS Node. In your code, you first need to declare a provider // Connecting to the Chainstack's WSS Node const provider = new ethers.providers....
Suhail Kakar's user avatar
3 votes
Accepted

Providing Metamask hooks only using node hosted on server

I work on MetaMask. I think MetaMask mostly does two things: It provides a web3 object to read from, a blockchain data source. It manages the user's keys, and by connecting them to the web3 API, ...
DanF's user avatar
  • 2,616
3 votes
Accepted

How to set truffle-hdwallet-provider as the Web3 currentProvider inside a web page

A solution is provided here. Essentially, you build the HDProvider, just as you would in truffle, and then pass it to Web3.
jsantos's user avatar
  • 106

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