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
1
vote
1answer
14 views

Scope Issue: Not successfully storing accounts after using web3.eth.getAccounts()

I am having trouble with the following code: var accounts = [] let accounts = await web3.eth.getAccounts((error, result) => { accounts = result; console.log(accounts); }); console.log(...
0
votes
1answer
11 views

What would web3.js respond with in this case?

I have a mapping to a struct in my contract mapping (uint=> Student) students; struct Student { bool passed; } Now I want to call a particular student with a particular ID to see if he has ...
0
votes
0answers
30 views

Alternative to Ethersweep

Im experimenting with the erc20 token. When trying to write contract on etherscan the Web3 connection just don't work, and I don't know why. But then I thought that perhaps Ethersweep could do ...
0
votes
0answers
55 views

How to send transactions to smart contract in batch?

I have this smart contract function: function addOneUser (User memory _user) public { bytes32 hash = keccak256(abi.encode(_user.name)); users[hash] = _user; } Using ...
2
votes
2answers
62 views

Analogue web3.eth.accounts.sign (from web3js) in web3py

There is a function web3.eth.accounts.sign in the implementation of web3js. But I cannot find the exact equivalent in web3py I don't see this. I found something similar to this — the signHash function ...
0
votes
1answer
22 views

How to send a transaction with large data ethereum?

I am trying to send an array of object (tuple) to smart contract. function addManyUsers (User [] memory _users) public { for (uint i = 0; i < _users.length; i++) { bytes32 ...
0
votes
1answer
20 views

Get return data from sendSignedTransaction

I need access to data returned by function that also changes state. Example: I have a contract live on testnet with a function that creates and then returns a new ERC20 token. contract MyContract { ...
0
votes
1answer
25 views

Uncaught TypeError: web3.eth.Contract is not a constructor

For whatever reason, when I attempt to set an instance of a contract in a javascript file, I get the following message in my console: Uncaught TypeError: web3.eth.Contract is not a constructor At ...
0
votes
0answers
17 views

Promise Function doesn't wait till transaction end

I am creating a session Contract then get it's public key using event on promise function 'loadSessionContract' but it run before 'creatSessionPromise' finish transaction so I got empty address what I ...
0
votes
1answer
21 views

Html interaction with smart contract via web3.js

I have a html code interacting with my smart contract via a local test rpc local host. I was just wondering if I deploy this contract to the main network instead of using test rpc, what should be the ...
0
votes
1answer
22 views

Do smart-contracts work as APIs?

Is it possible to put a smart contract "behind" a restful API, i.e. expose my contract functions and properties through restuful API where I can make RPC to it? Or does it work as an API already, but ...
0
votes
1answer
24 views

How to print “string” from Solidity in React?

My smart contract function is : function sNName(uint z)public view returns(string memory) { return abc[xyz[z].name]; } Where abc represents a mapping (bytes32 => string) In my .js file, I ...
0
votes
1answer
63 views

'types/values length mismatch',

Hey guys I had a problem with my return function here's my smart contract : pragma solidity >=0.4.0 <0.7.0; contract NewHello{ address owner; address newOwner; constructor()public{ ...
0
votes
0answers
28 views

Web3 provider in Unity

I working with projects on the blockchain. Making web apps which communicating with smart contracts, giving tokens or etc. For web apps, I need to get users wallet (Ethereum). I using these software/...
0
votes
3answers
61 views

How to call a smart contract function in a DAPP?

I am trying to make a DAPP. I followed this link - https://medium.com/@takleakshar/how-to-build-a-decentralized-full-stack-app-in-ethereum-and-react-42e63d45a208 This is how my 'Setup.js' looks. ...
1
vote
1answer
31 views

ENS name reverse is not working on Ethereum address

I'm trying to both resolve and lookup using "ethjs-ens" the lookup call is working correctly. However, the resolve call is throwing an empty error. The address I'm using on the reverse function is ...
0
votes
0answers
49 views

“evm: execution reverted”

solidity version:0.4.25 web3 version:0.20.1 I write a contract using solidity,and I have finished the test on remix web and it work successfully.When I want to call the contract using web3,the geth ...
3
votes
1answer
84 views

What is the standard for listening to ERC20 events?

Hi I am a bit confused here. The official EIP documentation states that event Transfer(address indexed _from, address indexed _to, uint256 _value) is how the Transfer event should look like. If I ...
0
votes
1answer
53 views

Web3.js batch request error: method.callback is not a function

If I try to run the example given here: https://web3js.readthedocs.io/en/1.0/web3-eth.html#batchrequest With the following code: const batch = new web3.BatchRequest(); batch.add(web3.eth....
1
vote
1answer
44 views

Which is faster: loop inside contract or loop of transactions?

I have this contract: pragma solidity 0.5; pragma experimental ABIEncoderV2; contract TestStruct { struct User { string name; uint256 age; } mapping (bytes32 => ...
0
votes
1answer
38 views

How to charge a fee in ethereum smart contract transactions

I need help on how to charge a transaction fee in ethereum smart contract using web3? Also which web3 API can be used to check the validation of enough gas on the frontend of smart contract?
0
votes
1answer
109 views

TypeError: this.provider.sendAsync is not a function

First I connected web3 with Infura. Then reading an ethereum account. I receive the following error while fetching account balance through node.js console. > web3.eth.getBalance(address, (err, ...
1
vote
1answer
55 views

How to listen for events at a specific contract

I am new to the world of web3 and trying to learn how to listen for events. I've been googling and reading for a while and can't seem to get something working. I'm able to subscribe to ...
0
votes
1answer
27 views

Passing array in web3.js as a function parameter

I am trying to estimate gasLimit for function that transfers funds to multiple addresses: const gasLimit = await multiTransferContract.methods .transferToMany(targetAddresses, amounts, tokenAddress)...
0
votes
1answer
32 views

Wrong estimation of gas while contract deployment

I have a smart contract: pragma solidity 0.5.3; import "./ERC20.sol"; contract Transfer { ERC20 private erc20iface; address private _owner; modifier validOwner() { require(msg.sender == ...
1
vote
1answer
27 views

Is there a way to obtain the same Hash using Keccak256 from Web3 and ZoKrates hash function such as sha256packed?

I am trying to use the hash obtained from keccak256 (applied to a number or input) and using it into sha256packet from ZoKrates (or other function) for comparing it with the Hash obtained in Zokrates ...
1
vote
1answer
59 views

Store data on Blockchain via Backend App

First of all, sorry about my bad english. I looked in the forum but I did not find a similar situation, but I apologize if I'm repeating something here. I need to develop an application that runs on ...
0
votes
0answers
22 views

Get the address of a contract without using Remix-ide

I'm studying Ethereum, I need to get the contract address for interact with web3, I can not use Remix-IDE for this since that I installed Kali as an operating system. How I get the contract address ...
0
votes
0answers
31 views

Cannot read property 'deployed' of undefined

Hello i try with web3 to run frontend with remix. The chrome shows the error from title for this line> App.contracts.Creation.deployed().then(function(instance) { I would love to help me!
1
vote
1answer
27 views

How to connect frontend to a node

I created 2 nodes . I connect an accounts to metamask. I connect the smart contract with remix on the node. Now i am trying to connect frontend with the smart contract with web3. In the index.html i ...
0
votes
1answer
25 views

What is the difference between web3 and window.web3

I'm very used to using web3 = new Web3(web3.currentProvider) and I saw here that MetaMask sample code is using window.web3 = new Web3(web3.currentProvider) What's the difference between using and not ...
0
votes
2answers
53 views

Can't get MetaMask wallet address on Firefox but Chrome is fine

I'm trying to get the current wallet address of MetaMask on my Firefox 67 but I keep getting nothing (empty array), except it says my MetMask is locked. But on Chrome 74 it works. FYI, my MetaMask is ...
0
votes
1answer
100 views

all web3 call methods returns null

I create my contract with the following code: pragma solidity ^0.5.0; contract Coin { function sayHello() public view returns(bytes32) { return "Hello"; } } truffle-config: module....
0
votes
0answers
41 views

Uncaught (in promise) DOMException: Failed to execute 'postMessage' on 'Window'

let web3Provider = web3.currentProvider; let ethersProvider = new ethers.providers.Web3Provider(web3Provider); Using the web3 current provider for creating the ethers provider causes a uncaught DOM ...
0
votes
0answers
39 views

How to filter MyEvent({ },{ }) to retrieve only the latest transaction in the array?

My code: instance.MyEvent({}, {fromBlock: 0, toBlock: 'latest'}).watch(function(error, event) { if (!error) { console.log(event); $('#events').html(event.transactionHash); } else { ...
0
votes
1answer
71 views

No web3.min.js while download Zip file from Github

I am following a youtube tutorial to make a simple dApp. In this tutorial he is telling to get Web3 from GitHub. I downloaded the Zip of Web3 from the GitHub and i get following folders and file after ...
0
votes
1answer
32 views

Producing a Hash of a File [closed]

I would like to upload a file to my UI and then produce a hash of it so I could later store it on Ethereum. Here is the code I am using to upload the file: <div> <label for="file input"&...
0
votes
1answer
39 views

HTML interaction with blockchain

I'm collecting temperature data from user on-chain. However, since cant get exact (live) time through my html code connected via testrpc to the blockchain I do so. Where post click a button, html ...
0
votes
1answer
58 views

Error when estimating contract deployment fee using web3.eth.estimateGas

When I run the code line below: let gasEstimate = web3.eth.estimateGas({from:myAddress, data: bytecode}) got and error: > Error: Node error: {"code":-32000,"message":"gas required exceeds ...
1
vote
1answer
43 views

Transfer erc721 token to another address

I'm currently using transferFrom / safeTransferFrom to transfer the token to another address but I encounter this error. Error: Error: invalid address (arg="to", coderType="address", value="...
0
votes
1answer
25 views

Web3 event listener - timing issue when immediately retrieving contract values

I'd like to be able to immediately get a struct value from a mapping after calling a function that updates the struct, however, when testing with Ganache, sometimes the event arrives to the listener ...
0
votes
1answer
29 views

web3 ens library - purpose of setText, getText against ENS name

I am looking at web3.eth.ens library, I can see methods setText and getText, which allows you to set and get key value pairs against an ENS name. What is the purpose of this? Also is there a way to ...
1
vote
0answers
55 views

How to use web3-react with truffle Dapp? any sample code / tutorial?

I am new to react and finding issues with the front-end of the Dapp application. Especially in web3 version > web3 1.0.0 I just heard about the web3-react and I think it will be a lot easier. I ...
1
vote
1answer
42 views

where does the metamask fits in Dapps architecture?

i am learning building Dapps. And i got to know to know about metamask. I've read about metamask is an ethereum wallet which we can use to sign Tx's without running a full node and inject web3 to ...
0
votes
0answers
25 views

web3.eth.getBlock in order

I am a beginner for Javascript & web3(0.20). I am using Metamask for watching allevents, and I need to get timestamp. I use getBlock.timestamp. Due to Javascript, timestamps are not inorder. I ...
0
votes
1answer
34 views

Object to Hex function (like in sign transaction)

I am reading the Web3 documentation about signing transactions (see example below). As I understand it, the "transaction object" gets turned into a hex string and enveloped, this is the "message". The ...
0
votes
1answer
64 views

How to hash multiple values including array keccak256 Solidity v5.0.x and web3 'Autodetection of array types is not supported.'

How can I receive the same hash in solidity and web3? Multiple values where one is a multi dimensional array. Solidity v0.5.x: pragma solidity 0.5.6; pragma experimental ABIEncoderV2; contract Hash{...
1
vote
0answers
105 views

Web3 in the browser

Importing web3@1.0.0-beta.55 in a stencil+typescript file for a frontend application directly triggers an error, even without using the imported Web3 object whatsoever. import Web3 from 'web3'; -> ...
0
votes
0answers
27 views

web3js batch execute method gives error

I have private/local network/chain setup. I'm building this with Nodejs-->expressjs. const contract = new web3.eth.Contract(abi, address); const batch = new web3.BatchRequest(); batch.add(contract....
0
votes
2answers
38 views

Cannot declare web3 object in JavaScript

When I try to declare a web3 object It's always undefined. I'm writting in JavaScript and using Infura as my provider for the ETH mainnet. I also tried with a local blockchain instead of Infura, but ...