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

Filter by
Sorted by
Tagged with
0
votes
0answers
6 views

MetaMask blocks web3 requests

I just set up a Block Explorer to interact with my private blockchain. The private Blockchain runs in a VM. The host system connects to the Block explorer. When I have meta mask installed in my ...
0
votes
0answers
7 views

How to signTransaction of a smart contract methods?

I have a smart contract contains this method: function addOneUser (User memory _user) public { bytes32 hash = keccak256(abi.encode(_user.name)); users[hash] = _user; } I want ...
0
votes
0answers
9 views

Payable function not working properly

Hi everyone hope I will be clear enough with the explanation because I couldn't find a proper solution. I am just trying to checkout an item with my buy function but it seems like I am stuck.Here is ...
0
votes
1answer
9 views

Load Smartcontract in Nodejs

I created the server based on golang. This server can load smart contract that is deployed using its address. It works on my local machine, but it does not work on EC2 instance. So I decided to ...
1
vote
0answers
10 views

EIP712 implementation for web3 1.0

I tried replicating the instructions in this article to implement EIP712 signing, however, it doesn't appear to work for web3 1.0 versions. https://medium.com/metamask/eip712-is-coming-what-to-expect-...
0
votes
0answers
18 views

invalid JSON RPC when using custom domain name

geth --testnet --networkid 3 --syncmode "fast" --datadir "." --cache=2048 --rpc --rpcport 8545 --rpcaddr example.ropsten.hk --rpcvhosts example.ropsten.hk --rpccorsdomain "*" --rpcapi="web3,miner,...
2
votes
2answers
30 views

Why can't I use a contract method in my Chrome console?

I am attempting to call a method from a smart contract from my chrome console. My dApps index.html file is deployed locally at http://127.0.0.1:5500. I set up web3 and instantiate a smart contract ...
0
votes
2answers
46 views

How to get response from Solidity Smart contract by Web3 client?

Here is the Smart contract code. I want to get the result of function of UserRegister by using web3. function UserRegister(string memory userName,uint feiyong ) public payable returns(string ...
3
votes
2answers
34 views

Alternatives to metamask [on hold]

What are existing alternatives to metamask with that works online inside existing browsers, that don't require installing a browser extension? What are some of the tradeoffs between them?
0
votes
0answers
10 views

How to filter by string parameter , web3 2.0.0-alpha.1 Solidity events?

I'm trying to filter some events , and I noticed since I updated the web3 to version 2.0.0-alpha 1 the event catch is a little bit different. I have a Smart Contract with this event : event ...
0
votes
1answer
21 views

Cannot Find Module Error for Truffle-contract

Error:- Uncaught Error: Cannot find module './truffle-contract.min.js' at c (web3.min.js:1) at c (web3.min.js:1) at index.html:27 <!DOCTYPE html> <html lang="en"> <head&...
1
vote
1answer
17 views

Trouble accessing an array inside a struct inside a mapping via web3

Here are a few relevant code snippets from my smart contract struct Constituency{ uint16 id; string name; uint64[] cans; } mapping(uint => Constituency) public constituencies; ...
-1
votes
1answer
16 views

Where is web3.eth.abi with the version of web3.js given with Metamask

Seems the docs doesn’t contain the answer. Looks like that part was moved elsewhere with latest transaction. The aim is to access encodeFunctionSignature() for knowing to which function name the ...
0
votes
1answer
34 views

Web3 - Assign nonce to smarct contract transact

I have a smart contract. I want to execute one of its state modifying functions. This is the code: const result = await smartContractObject.methods .addSomething(_valueToAdd) .send( { gas: '...
-1
votes
2answers
18 views

contractAddress: null

I use sendSignedTransaction to send the contract and return contractAddress: null let rpcUrl = "https://ropsten.infura.io/v3/6756e6f8f0e34482a262a7cf1d15f2c2"; var web3 = new Web3(new Web3....
1
vote
1answer
21 views

Getting an error when (attempting to) using Web3js

I'm trying to connect a smart contract to a very simply front end that has html/css/js. I keep getting an error when trying to use web3 to connect - I have the code below but the terminal is giving ...
1
vote
1answer
10 views

ganache test returns characters instead of numbers

mapping(uint256 => uint256) public amount; function saveAmount(uint256 _id, uint256 _amount) public { amount[_id] = _amount; } I have a function that saves amount in mapping. When I test ...
1
vote
1answer
23 views

Both web3.eth.accounts.create() and web3.eth.personal.newAccount() not working

I'm making a dApp on reactjs. I wanted to create a new account and have done it trying 2 methods this.web3.eth.personal.newAccount() this.web3.eth.accounts.create() I have attached the code below(...
1
vote
0answers
20 views

hexToNumberString not require in new web3 versions?

I have such code before let profit = await contract.methods.calculateFundProfit().call() profit = web3.utils.hexToNumberString(profit._hex) but after update web3 version, do I need do only this? ...
0
votes
1answer
21 views

getAccounts in web3 js undefined

I am working on dapp with web3js 1.0.0.37-beta with reactjs. I got blank in web3.eth.getAccounts. Following is my code App.js import React, {Component} from 'react'; import '../node_modules/...
0
votes
1answer
7 views

Get gas limit beforehand with Web3

I know that web3 exposes a function to estimate gas limit, but is it accurate when sending to a contract? AFAIK the amount of gas I'm gonna need if sending to a contract depends on the contract code, ...
0
votes
0answers
17 views

Solidity Error: Cannot destructure property `interface` of 'undefined' or 'null'

I've got his error in Solidity when compiling my test file: TypeError: Cannot destructure property interface of 'undefined' or 'null'. I know it is related to my compile.js file, but what is ...
0
votes
1answer
24 views

How to unlock account to deploy contract without using personal.unlockAccount()?

When I have account keystore file on geth node http://192.168.43.201:8545 , I can deploy a contract like below: const web3 = new Web3('http://192.168.43.201:8545'); ... const contract = new web3.eth....
0
votes
1answer
24 views

Web3 - Access return value of events

I want to get the value that my smart contract returns in javascript. Here is the contract. (version 0.4.25 - web3 version 1.2) pragma solidity ^0.4.25; contract SimpleStorage { uint public ...
0
votes
1answer
34 views

problem connecting web3 v 1.2.1 with metamask : 'currentProvider' of undefined

I am using Web3 v1.2.1 with nodejs v10 and following this link. I am having issue connecting with metamask,below is my code snippet: const Web3 = require('web3') const window = require('window'); ...
0
votes
1answer
22 views

Can't log struct member in truffle test

Contract : mapping (bytes32 => MyStruct) public myMapping; struct MyStruct { uint256 myMember; uint256 someOtherMember; } Test (Truffle) This works: let ...
0
votes
1answer
20 views

Code:const web3 = new Web3(window.web3.currentProvider) Error: window.web3 is undefined

I am going to connect my contract with the website.However,there was something wrong with the web3? I'm not sure. import Web3 from "web3"; const web3 = new Web3(window.web3.currentProvider); const ...
0
votes
2answers
13 views

How to prove existence of a function with estimategas

How can I prove the existence of a function in a smart contract with the EstimateGas ? Thanks.
1
vote
1answer
26 views

Solidity - Return value of Smart Contract Transact

Why do Solidity transact functions not return any value? Here is an easy example. I tested it in remix and web3. pragma solidity ^0.4.25; contract SimpleStorage { uint public storedData; ...
0
votes
3answers
45 views

Response stuck when creating contract

I am creating a contract on my local blockchain network using web3. On my node , contact is created and address is generated. But on node application, response is struck. Here is my node code: ...
1
vote
1answer
36 views

Which version of web3 shall i be using now?

I found the documentation of version 1.0.0 which was released on the 6th of August here. I was told that v1 is not stable and very different than earlier versions. But when i check the available ...
2
votes
1answer
24 views

How are we able to send 512 bit hash as a bytes32 variable?

I have a code that is working: solidity function checkSignature(bytes32 h, uint8 v, bytes32 r, bytes32 s) public pure returns (address signer) { bytes memory prefix = "\x19Ethereum Signed ...
1
vote
1answer
23 views

Get Ethereum private key from loom private key

I deployed my contracts to a local dapp chain with the private key generated by Loom. Since that private key is not compatible with the Ethereum one, I cannot use web3.eth.accounts.privateKeyToAccount ...
1
vote
1answer
28 views

How do I use web3js 1.0.0 in geth 1.9.0? I want to import an account whose address, private key and passphrase I have in my geth node

I am at Geth/v1.9.0-stable-52f24617/linux-amd64/go1.11.5 web3JS version is giving : > web3.version { api: "0.20.1", ethereum: "0x2712", network: "4", node: "Geth/v1.9.0-stable-52f24617/...
1
vote
0answers
12 views

Unknown account error when initiating transactions from remote node

I am using Ropsten network and trying to transfer ether from my metamask account to my another account using geth client. I am using the methods like eth.signTransaction, eth.sendTransaction in CLI, ...
0
votes
1answer
16 views

Solidity event not showing up from Web3.js

I'm trying to set up an event in Solidity and listen to it from Web3 but I keep getting a null response. Here's my code: The relevant part of the contract: event NewUser(string userid); function ...
0
votes
1answer
26 views

How do I create a MetaMask Connect request to auth a wallet with MetaMask

I am looking for how to authenticate completely in the browser with MetaMask, presumably by having it sign with some private keys and prove that the user owns a wallet that lists the corresponding ...
0
votes
1answer
42 views

Calling signature functions in web3.js 1.0 reports invalid address and cannot read address property

I am doing a project with inserted Metamask to achieve on-click blockchain account login. When I am calling the signature function web3.eth.sign("Hello world", "...
0
votes
1answer
27 views

Where Do I Find web3.min.js for Beta 55?

There is this issue on github (among several other duplicate complaints): https://github.com/ethereum/web3.js/issues/2623. There is also this stack question: How can the web3 library be imported in ...
1
vote
2answers
36 views

Can anybody Point out the Difference between Web3.eth.sendTransaction and web3.eth.signTransaction?

Do we need to sign the transaction by web3.eth.signTransaction after initiating transaction via web3.eth.sendTransaction. for example: when I do: web3.eth.sendTransaction({ from: accs[0], ...
-1
votes
1answer
31 views

MetaMask - RPC Error: The method personal_newAccount does not exist/is not available

When I execute following code then it show me: MetaMask - RPC Error: The method personal_newAccount does not exist/is not available if(typeof window.web3 !== "undefined" && typeof window....
3
votes
1answer
51 views
+50

signed message different on opera and metamask

I am using the following code to sign a message: web3.currentProvider.sendAsync( { jsonrpc: '2.0', id: 1, method: 'personal_sign', params: [ `My account is ${this.accounts[0]}`...
0
votes
0answers
11 views

Can web3js accurately estimate a transaction that includes an external call?

Can web3js accurately estimate a transaction that includes an external call? For example, will it be accurate in estimating: (bool _success, bytes memory _response) = _to.call.value(_value)(_data); ...
1
vote
1answer
22 views

How to get timestamp of an event log in emitted event from smart contract

I want to get the timestamp of an event. How can I get time of event fired, if the event data does not contain any time value?
0
votes
0answers
21 views

web3 error: private key length is invalid

I was trying to create my own wallet on etherum test network Rinkeby. When I successfully created wallet: const newAccount = await web3.eth.accounts.create() and got wallet address ...
0
votes
0answers
12 views

How to obtain data from a private PoA Ethereum Network?

I want to fetch data from a private PoA ethereum network running on a local computer. The data will be used for anomaly detection. I need contract interaction data (function calls etc.), to observe ...
0
votes
0answers
5 views

Prompt Metamask to send eth with Web3

I understand this as the pattern to send a transaction with web3: web3.eth.sendTransaction({ from: myaddress, to: toaddress, data: web3.eth.abi.encodeFunctionSignature('whitdrawETH()') ...
2
votes
0answers
20 views

What is the difference between signing a document, signing a transaction and signing a message? (very basic)

As per my limited knowledge in Ethereum, user can sign the object(doc, Tx, msg) for the security purpose and with the public key other user can get that object. But not understand the difference ...
0
votes
1answer
34 views

Why Web3 event callback fires multiple times same as the number of the solidity smart contract emitted that event in past?

I am just learning, solidity with react and web3 and I am facing the issue on page load the callback event of web3 called multiple time the number is same as I called a solidity function and that emit ...
0
votes
0answers
27 views

Cannot access myContract.events in web3.js version 0.20.7 [duplicate]

It seems that I do not have access to certain tools in web3js that allow me to subscribe to events. When I tried to use contractInstance.once('allEvents', callback) after instantiating a contract, I ...