Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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

0
votes
0answers
16 views

ERC721 Transfer Event issue

Looking at the open-zeppelin ERC721 Contract's code, I see that the very last thing that its mint function is doing is call emit on the contract's pre-defined Transfer event. My question is: how do ...
3
votes
1answer
74 views

The method eth_chainId does not exist/is not available

I'm having troubles when estimating the gas to call to one of the methods of my contract deployed in kaleido. I've successfully deployed the contract through Remix. Also from Remix I can call all my ...
1
vote
2answers
85 views

How do I implement simple JS code to deploy a compiled smart contract to ganache-cli? [closed]

Everything I've tried results in strange errors, and it's been difficult to get this working. I've been struggling with this for a while, especially having problems determining which versions of web3 ...
0
votes
1answer
27 views

how to use backup node in web3 connection?

node1= running on port 8545 => current synced block is 2000, and node2= running on port 3545 => current synced block is latest When i am using web3 into another page and print web3 object it ...
-1
votes
2answers
36 views

How to Learn Solidity [closed]

I know basic solidity but how i learn higher level solidity to make dapps ? What advance skill required for smart contract and Dapps development ? Where I can practice my skills ? Please Help Me. ...
2
votes
1answer
39 views

How do I resolve the DataCloneError when using web3 and react

I'm trying to add a small amount of web3 code to a react component. When I do so, I'm getting a DataCloneError. The component is as follows: import React, { Component } from 'react'; import Web3 from ...
0
votes
0answers
19 views

Web3 & Solidity - Automatically read ABI and Create Contract

Is there a way to automatically create a new Solidity Contract - from within a web3 JS file using the .json file created in a project's build folder after each compile? I have already figured out how ...
0
votes
1answer
27 views

Solidity Contract Needs Another Contract's Address

Is there a way for a Solidity contract to programmatically find out another solidity Contract's address? Right now I'm letting Contract A know about Contract B by hard-coding the address of B into ...
0
votes
1answer
134 views

Use solidity contracts public property and method in web3js.Error: Invalid bytes string given: 0x

I want to use contract's property and method by web3js: versions: "ganache-cli": "^6.3.0", "mocha": "^6.0.1", "solc": "^0.5.0", "web3": "^1.0.0-beta.47" Imooc.sol: pragma solidity ^0.5.0; ...
1
vote
0answers
30 views

web3.eth.getAccounts() yields an empty array

I first started geth:  geth --syncmode "light" --rpc --rpcaddr 127.0.0.1 --rpccorsdomain "*" --datadir ~/eth_blocks/ and then used: geth account new. I verified that there is a new entry in ~/...
1
vote
0answers
72 views

The object could not be cloned. && DOMException: Failed to execute 'postMessage' on 'Window'

When I try to sign a message with this simple function const signatue = await window.web3.eth.sign(hash, userAddress) I get an error. In firefox I get Unhandled promise rejection DOMException: "The ...
0
votes
0answers
28 views

Query Ethereum Blockchain for functions return value of a Specified Smart Contract

I want to get smart contract functions return value sent by a specified smart contract within a range of blocks. I found a [manual] working method to achieve this: async function getTxsByAccount(...
1
vote
0answers
15 views

All signed txs get reverted when interacting with testnet

I'm trying to call a contract deployed on Rinkeby. When I'm deploying it with truffle and interacting with any function it works, but with web3 I always get a revert. I use the following code: var ...
1
vote
1answer
19 views

Accessing 'constant' variables not working

I need to access some constant variables in a smart contract, but I'm not being able to. Here's my code: decimals = await contractInstance.methods.decimals().call(); 'decimals' is a constant in a ...
0
votes
0answers
31 views

How to detect web3 of mobile wallets?

I am working on a react application and just can't catch the web3 object of mobile wallets. Catching web3 in Metamask works like a charm. Here's my code so far: componentDidMount() { window....
0
votes
1answer
26 views

Wait a promise end before continue

i try to create a map with (address => bool) with web3js. I want to know if the address is a contract owner. So, i have to call "owners" function in my solidity contract. As you can see below : let ...
0
votes
0answers
13 views

web3.js contract instantiation failing

var Web3 = require('web3') var url = 'https://ropsten.infura.io/v3/xxxxx' var mycontract = '0x7eAd553D7E528Bdf12364177453f25bfa0682FD6' var contractAbi = [ taken from remix]; var web3 = new Web3(url) ...
0
votes
1answer
55 views

How to convert string to bytes32 properly?

In my solidity I'm using a mapping like this: mapping(bytes32 => uint) items; constructor() { items["test"] = 2; } function getItem(bytes32 key) returns(uint) { return items[key]; } ...
2
votes
2answers
80 views

Cannot create property 'from' on string

I'm trying to call a contract method from web3js. The contract is deployed in a local ganache. This is my full code // Instantiate contract const provider = new Web3.providers.HttpProvider("http://...
0
votes
0answers
14 views

web3 is not getting detected while migration in truffle [duplicate]

I am trying to deploy the contract in ropsten. In that process I use web3 for a conversion. Due to this the migration fails as mentioned below. Please assist me in resolving this. I have also tried ...
2
votes
1answer
25 views

Clarification on “password” argument for web3.eth.personal.sign

Context: I'm fairly new to web3, and as we all know it's developing quite regularly. I'm working towards a "sign in with Metamask"-type functionality using web3@1.0.0-beta.46. Most of the docs/...
0
votes
0answers
50 views

Cannot sign a message with web3js (invalid from address)

So I am trying to create a signature of a string, but I cannot do that, as I always get error stating MetaMask - RPC Error: Error: WalletMiddleware - Invalid "from" address. (code: -32603). I am ...
0
votes
0answers
52 views

How to access the return value of function of ethereum contract using web3 in javascript?

I have written a basic hello world! smart contract and deployed using testrpc and truffle. I have a function in the contract that returns a value and i am using this function and the value it returns ...
0
votes
0answers
14 views

eth_sendTransaction doesn't exist when using Infura node

I'm trying to sign a transaction offline and then send it using sendRawTransaction since I'm connected to an Infura node. My raw transaction looks like this let rawTransaction = { "from":...
1
vote
1answer
41 views

TypeError: Cannot read property 'fromWei' of undefined

My below code is working fine Web3 = Require('web3'); const walletAddress = '0x8690F1feff62008A396B31c2C3f380bD0Ca6d8b8'; const web3 = new Web3(new Web3.providers.HttpProvider(testnet)); var balance =...
1
vote
1answer
32 views

how to test overloaded function in truffle?

I recently upgraded truffle to the newest version. Now it does not automatically detect overloaded functions anymore. Before, I could just do the following: await contract.function({ from: accounts[...
0
votes
1answer
28 views

Interaction with deployed contract over private blockchain Error: invalid address

I have deployed a smart contract over my private ethereum blockchain using geth. Smart Contract pragma solidity >=0.4.22 <0.6.0; contract GreenPoints { string public name; string ...
0
votes
1answer
60 views

web3.min.js is missing in ./node_modules/web3/dist

I am following the below tutorial to create implement blockchain using web3. https://medium.com/coinmonks/interacting-with-ethereum-smart-contracts-through-web3-js-e0efad17977 When I am using npm ...
1
vote
2answers
94 views

web3.eth.Contract(abi, address) doesn't return contract instance

i'am trying to make a instance of my contract in js using web3, but when I use the function web3.eth.Contract(abi, address) the result is not the expected(I take the ABI from remix). this is the code:...
0
votes
1answer
25 views

Is there any way to decode to_address from getTransaction(hash).input of a token transfer?

Here is my code, web3.eth.getTransaction(txns.transactionHash,function (err,res){ console.log(res.to); // consoles contract address var input = res.input,erc20=input.slice(0,10); if(erc20 == '...
0
votes
1answer
38 views

web3.eth.getAccounts() never give any output

const deploy = async () => { **var acct = await web3.eth.getAccounts();** console.log("ac", acct); } deploy(); even the console is not getting printed,what could be the reason? ...
0
votes
1answer
19 views

Solidity returning address to javascript when uint was requested

I'm early in learning solidity (that's probably obvious). No idea why I'm getting this result. medsToBeDeveloped has a length of 0 at begining uint [] medsToBeDeveloped; function returnProductID(...
1
vote
1answer
37 views

How to use local Metamask account with Infura Node [duplicate]

I'm building a DApp using web3js that sends ERC20 Tokens from a browser Metamask account to an escrow contract on the Rinkeby testnet. I'm using a Rinkeby node from Infura, and when I call web3.eth....
0
votes
2answers
37 views

Is there a way to capture the require / revert failure reason?

In my contract I have a bunch of checking at the start of a public function, something like this: require ( prx < 1e18, "Value prx too high") require ( prx != 0, "Value prx cannot be zero") if (!...
-1
votes
1answer
26 views

Problem retrieving array of struct with web3js

I'm trying to return the struct values contained in array everytime i push a button thet call inserimento and ritornavalore functions. here is my code in solidity: pragma solidity ^0.5.1; pragma ...
0
votes
1answer
58 views

BigNumber Error: new BigNumber() not a base 16 number:

I'm new to Ethereum and javascript so hope someone can help me with this as none of the other answers on BigNumber help me understand why this won't work for me. I've tried converting the number to a ...
0
votes
1answer
27 views

VM error: invalid opcode while trying to execute buy function on Remix IDE

I am using following code for custom token on ethereum. pragma solidity >=0.4.22 <0.6.0; contract owned { address public owner; constructor() public { owner = msg.sender; }...
2
votes
2answers
26 views

TruffleSuite contract class or Web3^1.0 contract class for production code?

Starting out with blockchain development and I'm coming across many sources/courses that recommend the Truffle/Contract class for interacting with deployed contracts because of "ease of use". But Web3^...
0
votes
2answers
50 views

How to pass arguments to the constructor while testing an contract using web3

I need to test my contract using web3 and ganache-cli. In my contract, I have to send an argument to the constructor function. How to do it while deploying it with web3. factory = await web3.eth....
0
votes
0answers
19 views

Alternatives for offline signing

I want to execute the method1 of my contract from web3js. And I want to sign the transaction offline, I mean with web3js, and not to delegate that in the node. I've tried these 2 approaches. Both ...
0
votes
1answer
39 views

Facing UnhandledPromiseRejectionWarning warning message in web3 infura

So far, I'm trying to get transactions list using web3 & infura by websocket provider. Here is my code const Web3 = require("web3"); const web3 = new Web3(new Web3.providers.WebsocketProvider('...
0
votes
1answer
34 views

Specify an alternative node (IP:Port) for Drizzle, if there is no MetaMask or Web3-enabled browser

Drizzle will automatically use the injected Web3 object. But if there is now Web3 object, Drizzle will try to connect to ws://127.0.0.1:8545'. How to configure Drizzle to connect to Infura.io for ...
0
votes
1answer
60 views

Web3 not connecting with ropsten through infura

so my truffle based application is communicating fine with my smart contracts on my private network, ganache and ganache-cli. I then deployed it to ropsten where i used the endpoint i got from infura....
1
vote
1answer
16 views

Web3 1.0 Nested contract promises

What is the best way to handled nested contract call with web3 1.0? I'm trying to collect all data needed and format it into something useable. It could require 2 or 3 calls though. Is there a easy ...
0
votes
1answer
35 views

Invalid JSON Response while connecting DApp, Metamask and Backend

I am getting some error(picture below) while trying to connect DApp with a backend. One day ago, everything worked fine, now I got an error: "basic auth failure". Contracts are deployed on Ropsten ...
0
votes
0answers
33 views

Revert on ERC20.transferFrom

I am getting Error: Returned error: VM Exception while processing transaction: revert when testing MyContract.deposit() Here are simplified versions of my code to highlight where the issue is ...
3
votes
2answers
33 views

Passing '-1' to a solidity function which takes a 'uint256' argument as input

Suppose I have: function func(uint256 x) external { ... } I would like to test this function via web3.js, with the maximum possible value of x. In a Truffle test, I have noticed that I can ...
2
votes
0answers
30 views

Why I can't use two functions with same name, but different parameters

I have a function which returns address but it gives me error if I try to read it. I'll explain by a quick example: Solidity: contract TestOneReturn { mapping(uint => uint) m_Data; ...
1
vote
0answers
18 views

Error: Cannot create instance of X; no code at address

Having a little issue. I have deployed a Mock ERC20 contract on development network like so: const ERC20Mock = artifacts.require("ERC20Mock"); module.exports = async function(deployer, network, ...
0
votes
0answers
14 views

Ethereum web3 Browser Only functions

Two of the functions of web3 - web3.eth.accounts.wallet.load - web3.eth.accounts.wallet.save Mentioned in the Doc of web3, these are browser only functions. Already tried to test these function ...