Questions tagged [web3js]

Javascript API and library for Ethereum To develop applications on Ethereum, you can use the web3 object provided by the web3.js library. Under the hood it communicates to a local node through RPC calls. web3.js works with any Ethereum node, which exposes an RPC layer. https://github.com/ethereum/wiki/wiki/JavaScript-API

2,192 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
8 votes
1 answer
2k views

getting started with geth and ENS commands: Error: invalid address

I'm starting from square zero, sorry. I'm just trying to get a javascript console up and running so that I can learn more about ENS: http://docs.ens.domains/en/latest/userguide.html#resolving I've ...
7 votes
3 answers
6k views

sign transaction in web3 with metamask

I'm trying to make a signed transaction in browser with web3 injected from metamask and send the transaction to my backend-server and then submit it to blockchain. However, it's hard to find how I can ...
  • 73
7 votes
0 answers
935 views

How to Catch Connection Issues to Web3 Provider using Web3.js

My node.js script is able to successfully connect to the Web3 provider when both the private key (using truffle-privatekey-provider) and the provider host URL are correct. let privateKey = ..., ...
  • 1,117
6 votes
0 answers
4k views

Can gas price and amount of gas be automatically set by metamask, or are they required to be set via code in web3.js (EIP-1559)?

I am using web3.eth.Contract to deploy a smart contract to the ropsten testnet. To interact with metamask I am using window.ethereum. I deploy the contract via the code below that I found on https://...
6 votes
0 answers
815 views

Why does Ethereum use JSON-RPC and not gRPC?

I am fairly new to networking protocols especially JSON-RPC and gRPC as they are not nearly as common in web development as REST. I was reading around and seems like gRPC generally performs better. So ...
  • 161
6 votes
1 answer
1k views

Unit testing a Solidity Library function with a struct memory argument

I am trying to unit test a Solidity Library contract function using truffle and web3. My simplified Library contract looks like this: pragma solidity >=0.5.16; pragma experimental ABIEncoderV2; ...
  • 159
6 votes
0 answers
998 views

How to get ethereumjs-abi's soliditySHA3 and web3 sign equivalents in ethersjs?

Hello I'd like to create a hash using ethersjs that encodes a number of arguments. I previously used ethereumjs-abi's soliditySHA3 function but not sure which of ethersjs crypto utilities is the ...
  • 187
6 votes
0 answers
530 views

Truffle test of two transactions during the same block

I'm trying to test a solidity function that only allows it to be called once per block. E.g. (my desired functionality): Tx1 calls Fn during block #100, and when successful sets a boolean flag for ...
  • 61
6 votes
2 answers
1k views

Web3 Event Filtering timeout

This is the code I use to get all events from a certain contract. Solidity: event NewEvent(address indexed contractAddress, address newBOPAddress, address payer, uint commitThreshold, bool ...
  • 71
6 votes
2 answers
633 views

How to access dynamic list from web3?

In my application players can create and join games. I store every game in a mapping(uint => Game), and send out a GameCreated event whenever a game is created. My issue is efficiently getting a list ...
  • 106
6 votes
0 answers
5k views

Use of web3.js batch requests

The web3.js API allows for synchronous RPC batch requests with the example given as: var batch = web3.createBatch(); batch.add(web3.eth.getBalance.request( '...
  • 4,220
6 votes
1 answer
871 views

Problem with start() in web3-provider-engine

While trying to connect to a provider(infura) I get the above error below is the full stack trace: bundle.js:54318 Uncaught TypeError: this.provider.sendAsync is not a function at Web3Subprovider....
5 votes
1 answer
401 views

Does anything change on getGasPrice( ) in Web3js after EIP-1559?

Using getGasPrice in web3js returns the last few blocks median gas price. After EIP-1559, the fees system is divided into Base + Tip. My question is, what is returned using getGasPrice after EIP1559? ...
  • 990
5 votes
0 answers
2k views

How to convert my metamask private key into 32 bytes hexa

How to convert my metamask private key into 32 bytes hexa ? i am using web3 to start trading on pancake but when i try to convert my bsc metamask phrase keys into hexa is like 150 bytes but require ...
5 votes
0 answers
570 views

How to continuesly fork mainnet on latest block

How do I keep the fork mainnet use the latest block using web3? I need to fork mainnet to latest block before I send the transaction What originally i do is just run the ganache fork command which ...
  • 327
5 votes
0 answers
831 views

How to mimic abi.encodeWithSignature in web3?

I have the following function that I would like to test. function createPlanet(bytes memory _data) public returns (address) { emit ProxyCreated(planetImplementation); emit ...
5 votes
0 answers
3k views

Contract call: data out of bounds

I'm working on a nextjs/react project in which i want to fetch the health factor of an address on AAVE. This can be done by calling getUserAcountData(address) on the lending pool contract. I can ...
  • 380
5 votes
1 answer
771 views

Can't debug transactions that fail during the Web3.js estimateGas() call? No Tx Hash

NOTE: I am doing my work with the Ganache v1.2.2 GUI client on a Linux Ubuntu 18.04 station. There are many revert errors that happen during the estimateGas() call that precedes the actual Web3.js ...
5 votes
1 answer
1k views

web3.eth.getBlock returns null

I have a very similar problem as https://github.com/paritytech/parity-ethereum/issues/8788 When I use web3.eth.getBlock for the first 1 million and latest 50,000 blocks (approximately), I get the ...
  • 51
4 votes
1 answer
2k views

Web3 error: "value out of bounds" when passing in value for smart contract call

When calling a function on a smart contract that takes a tokenID, I pass in the tokenID into web3 - but web3 then parses that string into another value it seems, pads it to the left with a ton of ...
  • 531
4 votes
1 answer
2k views

how can i translate the ethers.js "getSigner" utility to web3?

I have a web3 object but I'm working off an example that uses ethersProvider.getSigner(). Is there an equivalent (or mostly equivalent) in the web3 library? For reference, the ethersProvider is ...
  • 403
4 votes
0 answers
11k views

Get RPC URL / IP of Metamask's current provider

Suppose I have multiple copies of the same dapp running on different servers which do not directly communicate with each other, for testing purposes, and can manually interact with different dapp ...
  • 555
4 votes
1 answer
144 views

Most efficient way to get all non-zero storage locations for a smart contract?

I'm looking at a mainnet smart contract and want to figure out all storage positions/slots where the storage has a non-zero value. Is there a way to do this other than replaying and tracing all ...
  • 935
4 votes
0 answers
443 views

How to access txpool pending transactions using Netherum?

I want to get list of transactions which are in pending state & queued state in txpool. I can see these transactions in pool using txpool.inspect command. I tried code given in nethereum sample ...
  • 108
4 votes
0 answers
133 views

Retrieve MetaMask version in web3.js

Is there a way to determine the version of the currently installed MetaMask extension from web3.js? I can't find it by inspecting the Web3 instance.
  • 423
4 votes
0 answers
2k views

Mining hangs on Generating DAG in progress

I am trying to initialize rpc using the below command and start miner using miner.start(1); geth --rpcapi eth,web3,personal --rpc --networkid=15 Mining starts successfully with below logs but it ...
  • 395
4 votes
1 answer
260 views

Estimated gas is always low

web3.eth.estimateGas is always calculating low gas for the transaction. Here is a reference to a trasaction in ropsten. https://ropsten.etherscan.io/tx/...
4 votes
0 answers
396 views

Is it possible to see the event log when using eth_call?

I want to perform a transaction locally (with the call method in web3 which perform a eth_call RPC call). It returns only the return value of the function called and I want to see the event log. I ...
  • 362
4 votes
0 answers
353 views

Web3 js events not listening after 5 mins of idle time

My contract is deployed on ropsten infura test-network and that contract has events which gets fired when there is some transaction. contract file function functionName(address from, address ...
  • 71
4 votes
0 answers
93 views

How to do a disaster recovery in private chains?

How can I do a disaster recovery on a private chain running ethereum, say for instance Quorum ?
  • 194
4 votes
3 answers
3k views

Correctly deploying contracts with web3 1.0 and testrpc (invalid opcode error)

I followed the following tutorial: https://medium.com/@mvmurthy/full-stack-hello-world-voting-ethereum-dapp-tutorial-part-1-40d2d0d807c2 Now this tutorial is not using the recent version of web3 but ...
4 votes
0 answers
265 views

how to get revert at the previous timestamp of evm in testrpc

I am testing my contracts so at some point i need to increase the timestamp of evm that i achieve through evm_timeIncrease but now i want to execute some functions on the basis of current timestamp ...
4 votes
3 answers
1k views

Importing a contract from another contract in NodeJS app

I'm using a function in my NodeJS app to deploy contracts. The user inputs the contract he wishes to deploy and the app deploys it. The structure of the app is . ├── app │   ├── models │   │   └── ...
  • 841
4 votes
0 answers
393 views

Contract execution fails with Web3 but works with Remix

I am dealing with a very simple smart contract: contract MyRegistry { struct MyEvent { string date; // yyyy/mm/dd string desc; // potentially long string uint count; // &...
4 votes
0 answers
414 views

How to create my own wallet and own blockchain explorer?

I'm running my own private/permissioned ethereum blockchain via geth on Ubuntu. How can i interact with my blockchain to visualize accounts, blocks, transactions etc...? I've tried a lot of tutorials ...
  • 544
3 votes
0 answers
561 views

Incompatible EIP155-based V 1 and chain id 1

It's my first question here so please don't be so strict. I have such a scenario: I start learning how blockchain works, downloaded truffle, ganache cli, created an account on infura and all that ...
  • 146
3 votes
4 answers
1k views

I keep getting nonce is too low when using truffle to call functions on contracts even though this works fine on remix.How can I fix this

I keep getting the nonce is too low when running functions with sub transactions on the kovan test net is there a way I can stop this from happening?these sub transactions are making transactions with ...
3 votes
0 answers
668 views

tx fee (5274661132.35 ether) exceeds the configured cap (1.00 ether) Web3 JS

New to web3 JS. using Binance Smart Chain (mainnet) :( I am getting this error: tx fee (5274661132.35 ether) exceeds the configured cap (1.00 ether) Below are my parameters (done on php for some ...
3 votes
0 answers
160 views

What's the type (always 0x0) field of a transaction about?

Using web3 you can get all transaction of a block web3.eth.getBlock: const web3 = new Web3(provider); const currentBlockNumber = await web3.eth.getBlockNumber() // true means that transactions should ...
  • 131
3 votes
0 answers
259 views

How can I do contract call transaction from Metamask qr code scan?

I have a payable function in the smart contract that takes some ether from the sender and does some tasks. I want to generate QR code for this contract call transaction so that user can scan and ...
3 votes
0 answers
939 views

What reason? "Unhandled Rejection (Error): replacement fee too low "

I am going to swap two BSC tokens using etherjs. I sent approval for a transaction and then I sent a swap transaction. I am using a Pancakeswap v2 router. I had this error. Unhandled Rejection (Error):...
3 votes
1 answer
3k views

How to send correct SwapExactEthForTokens params types on ethers/web3.js?

I need to know how to send correct paramaters / paramater types as in what does the parameter type has to be is it a hex number , a string ? help would be massively appreciated. Notes: 1)i cant set ...
3 votes
1 answer
688 views

web3 subscribe to pendingTransactions for a given contract?

Is it possible to only subscribe to a specific contract for pendingtransactions using web3.eth.subscribe? The docs dont show any parameters besides a callback function, so the result shows all pending ...
  • 161
3 votes
0 answers
1k views

Gas limit too low when using transaction data field

I am using web3.js to send a transaction. This is the code that I have currently: async function sendTx(tran, ethAddress, privateKey, value=0) { var tr = { chainId: await web3.eth....
  • 133
3 votes
0 answers
1k views

How to create a wallet with web3.js

From what I understand, a wallet is a smart contract and in order to create a wallet, you need to deploy the contract to the blockchain as stated here, which is different from creating accounts. When ...
  • 727
3 votes
1 answer
957 views

How to get a list of all token holders using ethers.js + metamask

Is there any way, using ethers.js and metamask, to build an array of all current token holders? I would need this to my project which I'm currently working at. I know I can download the entire ...
  • 701
3 votes
2 answers
7k views

How to generate solidity encode function signature from Javascript?

What I am trying to achieve is like , i should be able to call a set of solidity functions dynamically based on some criteria. i'm using call() method to achieve the same. (bool success, bytes memory ...
3 votes
0 answers
624 views

geth javascript console: web3.eth.subscribe ==> "Object has no member 'subscribe'"

I must be missing something -- I am trying to use the web3.eth.subscribe() function in my geth node's javascript console and there is no subscribe function. Welcome to the Geth JavaScript console! ...
3 votes
0 answers
2k views

Swap tokens to Ether on Uniswap V2 TRANSFER_FROM_FAILED

I am trying to swap DAI to ETH on kovan testnet my wallet and contract both have DAI tokens. Whenever I swap the token through web3 the transaction fails Fail with error 'TransferHelper: ...
  • 327
3 votes
0 answers
1k views

EIP-712 typed signature for arrays

I'm trying to generate a typed signature for an array in JavaScript based on EIP-712 and using eth-sig-util. My problem is that I need to sign an array. It says in the specification to use Type[] or ...

1
2 3 4 5
44