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

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

The tag should be for version-agnostic questions only, but many past questions will mean web3js-v0.x

6141 questions
44
votes
5 answers

How to detect if on mainnet or testnet?

Is it possible to figure out whether the network is mainnet or testnet (Ropsten) from web3.js? Or through MetaMask?
Hector
  • 443
  • 1
  • 4
  • 5
28
votes
1 answer

What is the difference between web3.eth.sign, web3.eth.accounts.sign, web3.eth.personal.sign functions?

Which function should be used to sign message locally? Which function is the most secure?
user652061
  • 473
  • 2
  • 5
  • 9
25
votes
6 answers

Invalid JSON RPC response: undefined, when running web3.eth.accounts (Node)

I'm very new Ethereum and trying to follow this tutorial: https://medium.com/@mvmurthy/full-stack-hello-world-voting-ethereum-dapp-tutorial-part-1-40d2d0d807c2 But when I run: web3.eth.accounts I get an error: Error: Invalid JSON RPC response:…
tim_xyz
  • 397
  • 1
  • 3
  • 7
22
votes
6 answers

Decode input data on transaction

I have an ABI and the input value of the transaction and want to know what function has been called on a contract and with what arguments (one or multiple of different types), preferably using geth, JSON-RPC and some pseudo code that I can then…
migu
  • 941
  • 2
  • 10
  • 18
17
votes
2 answers

Detect if web3 provider has successfully connected

I am connecting to local node from browser like: web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); If there is no node running at localhost, I see an error in browser console: Error: Invalid JSON RPC response: "" Is there…
hohoho
  • 293
  • 1
  • 2
  • 10
15
votes
1 answer

how to get erc20 token balance using web3

I am still new with web3 How can I get balance of token? On ropsten network, I have 100 LINK token. Below is my code const Web3 = require('web3') const rpcURL = 'https://ropsten.infura.io/v3/xxxx' const web3 = new Web3(rpcURL) let tokenAddress =…
webmaster
  • 153
  • 1
  • 1
  • 6
15
votes
3 answers

How to find contract creation block time with web3?

Is it possible to find out in which block a contract was created using web3?
0xcaff
  • 2,477
  • 1
  • 14
  • 29
14
votes
1 answer

Error: web3.toWei is not a function

Using Web3 version 1.0 and getting the following error: web3.toWei is not a function
Muhammad Altabba
  • 2,157
  • 1
  • 15
  • 31
14
votes
6 answers

Web3.js : eth.sign() vs eth.accounts.sign() -- producing different signatures?

I'm getting to grips with web3.js and have noticed an unusual issue with signing data. When I sign a string with the web3.eth.sign() method, I am getting a different signature than if I use web3.eth.account.sign(). Note this latter method takes the…
nervous-energy
  • 243
  • 1
  • 2
  • 5
11
votes
2 answers

How to get the "birth block" of a contract?

How does one query the "birth block" of a contract using web3?
will_durant
  • 1,154
  • 1
  • 9
  • 21
9
votes
3 answers

Invalid parameters: must provide an Ethereum address. Code -32602

Here is the transaction I am trying to send using web3.eth.sendTransaction: { data: "0x11a861a700...." from: "0x8ccb1711ea5562596f146608fdcf27ccf0d5429c" gas: "0x6b540" gasPrice: "0xaf16b1bb3" nonce: "0x0" to:…
luiquao
  • 191
  • 1
  • 1
  • 4
9
votes
3 answers

Error: connection not open on send()

I'm using "web3": "^1.2.4" This is how I connect to 'wss://kovan.infura.io/ws' const web3 = new Web3(new Web3.providers.WebsocketProvider('wss://kovan.infura.io/ws')) instance = new web3.eth.Contract(ABI, ADDRESS); Here I am trying to call…
Venkatesh S
  • 93
  • 1
  • 1
  • 4
9
votes
4 answers

Web3 is not defined Error

I'm trying to create a npm module with functions for interact with the ethereum blockchain, for the interaction i'm using the web3js API and i will put this module inside the my new module. In my packaje.json i put this: "dependencies": { …
Gawey
  • 814
  • 2
  • 8
  • 23
8
votes
2 answers

Metamask error: "Transaction Error. Exception thrown in contract code." (plain HTML + JS front)

I successfully implemented a smart contract using remix in the Rinkeby testnet, and can interact with it from remix. Now I'm building a simple frontend for it but although I have been able to obtain one of it's public variables, I'm not able to call…
Fabio Hildebrand
  • 331
  • 1
  • 2
  • 5
7
votes
1 answer

web3.eth.sendRawTransaction is not a function

This is the code i'm using to send payment from one address to another. But why do i get this error? TypeError: web3.eth.sendRawTransaction is not a function Here is the code im using var Web3 = require('web3'); var Tx =…
shawn
  • 399
  • 2
  • 8
  • 14
1
2 3
28 29