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 ...
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"));
...
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 ...
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 ...
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(...
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 ...
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 ...
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 ...
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 ...
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 (...
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.
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.
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 ...
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 ...
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(...
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 ...
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 ...
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.
...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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...') ...
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/...
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 ...
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....
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, ...
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.
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
web3-providers × 312web3js × 174
metamask × 54
ethers.js × 41
solidity × 38
go-ethereum × 29
infura × 27
javascript × 22
remix × 20
web3.py × 18
react × 17
blockchain × 15
ethereum-wallet-dapp × 15
truffle × 14
nodejs × 13
dapps × 12
contract-deployment × 11
events × 11
ethereumjs × 11
wallets × 9
json-rpc × 9
ganache × 9
websocket × 9
contract-development × 8
ether × 8