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
1answer
18 views

How to create account by web3 0.20 version?

I try to create new account by using web3, i found that I can only do this in 1.0 of web3 but not in 0.20 version? it does not support personal.newAccount
7
votes
5answers
5k views

How to keccak256 multiple types in web3js to match Solidity keccak256?

if I keccak256(string1, address1) in Solidity, and then use web3.sha3(string1, address1) in web3.js, I get different results, even though when I do both with only string1 as a single argument, they ...
0
votes
1answer
490 views

Simple event watching with testrpc - unexpected output

Working with this example, I've been attempting to utilise event watching from the web js api. Window 1 (a testrpc instance with filled account): testrpc -a 1 Window 2 geth attach rpc:http://...
0
votes
1answer
309 views

web3 contract TypeError: 'apply' is not a function

I'm Trying to call the apply function on the contract ABI but I'm getting: TypeError: 'apply' is not a function at :1:1 > myContract { abi: [{ constant: false, inputs: [{...}], ...
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 ...
1
vote
0answers
127 views

Solidity and Web3js codes are not working inside the private Ethereum(geth) network but same codes are working in public ethereum

geth version : 1.9.0-stable-52f24617, node version : v10.16.3, npm version : 6.9.0, web3 version : -- web3@1.0.0-beta.36. genesis.json: { "config": { "chainId": 9663080, "homesteadBlock": 0, "...
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
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]}`...
3
votes
2answers
6k views

How can I get my address via web3?

I'm using web3, truffle and testrpc. In my smart contract, some of the functions can only be called by the owner (or creator) of the contract (i.e. onlyOwner functions). So, I've defined some ...
0
votes
1answer
700 views

TypeError: web3.eth.getTransactionCount(…).then is not a function

I'm using web3 version '^0.20.6' in my node application and did following for connecting to web3 but still getting the error while calling the method getTransactionCount. const Web3 = require('web3');...
2
votes
4answers
599 views

Tracking tokenholders of a token with web3

If I have a token address how can I navigate and find certain things like: tokenholder addresses transactions for the token holders including when they made the transaction I'm new to smart ...
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 ...
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 ...
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,...
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?
1
vote
1answer
337 views

How to create wallet with web3j and web3swift like with web3js web3.eth.accounts.create(); function?

With web3js v1.0.0 you can create accounts with web3.eth.accounts.create(); and access the public address and private key with newWallet.address and newWallet.privateKey. How can you do this with ...
3
votes
1answer
807 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
1answer
720 views

Using injected web3.js in Vuex as a plugin

I would like to use web3 inside the store as a Vuex plugin, so I can call this.web3 inside actions and mutations without having to pass the web3 instance from my components to the store. But since the ...
0
votes
2answers
1k views

how to get the token transaction history via web3.js (0.20.6)

set up node.js + web3.js (0.20.6 version) + and using infura for the httpProvider I've figured out and successfully sent erc20 tokens using the web3.js, (after a lot of googling... complete noobie ...
1
vote
1answer
2k views

How to pass a parameter to a function in web3?

I have a button that executes a function in a solidity contract like this: <a href="#" onclick="solidityFunction()" class="btn btn-primary btn-block">Execute Function</a> The ...
2
votes
2answers
487 views

Cannot read property 'getBlock' of undefined

I'm having an issue with running truffle test on a Javascript test. I get the error TypeError: Cannot read property 'getBlock' of undefined. I am trying to get the time of the latest block by using a ...
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; ...
0
votes
2answers
18 views

web3js returns non-checksumed addresses!

Why does web3js 0.20.6 returns all-lowercase addresses on contract creation not a checksumed address?! How to deal with this trouble?
1
vote
1answer
237 views

How to confirm request in Parity

enter link description hereI send a transaction with contract. I use unlock account to account it. It can skip the first confirm. Which is asked to confirm deploy. But it can't skip the second confirm,...
1
vote
1answer
692 views

Difference between window.ethereum and window.web3?

If I log the two functions, I get two objects, that both contain for example selectedAddress, but the structure of the objects seem different. I couldn't find a comparison in the documentation. I ...
2
votes
1answer
26 views

Automatically determine the use of call or sendTransaction based on the method type

In web3.js version 0.x: The web3 module automatically determines the use of call or sendTransaction based on the method type. So for example, instead of doing: myContractInstance.myMethod.call(...) ...
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&...
0
votes
1answer
316 views

“Error: VM Exception while executing eth_call: invalid opcode” when accessing array

I'm trying to incorporate storage in a smart contract where participants of the contract will have their address stored in a address[] look up table participationAddressLUT. The contract initializes ...
1
vote
2answers
2k views

Out of gas when executing contract via web3 js

I am having a trouble invoking contract via web 3 js in browser. I am using truffle develop and have migrated and run tests successfully. I am also getting the info when I console.log the contract....
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
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
293 views

Javascript to display multiple records from a struct

I am trying to build some Javascript using Web3js to list out nested structs. Specifically, I have designed a customer struct through a mapping. I have nested in the customer struct two additional ...
0
votes
1answer
472 views

Solidity - Ballot Example

I have this following Ballot contract: pragma solidity ^0.4.11; /// @title Voting with delegation. contract Ballot { // This declares a new complex type which will // be used for variables later. // ...
1
vote
1answer
401 views

How to deploy a contract using metamask and the callback?

I'm trying to deploy a new contract with metamask (in my javascript frontend app). The problem is that, when the receipt is returned, the address is "undefined" since, I suppose, the transaction is ...
2
votes
3answers
1k views

Accessing web3 object in Chrome terminal using React

I am receiving a "not defined" error when trying to access the web3 object in Chrome terminal. My current setup: running testrpc web3 object successfully instantiated in App.js built app using React ...
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 ...
-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 ...
5
votes
3answers
3k views

Automatically update account balance with web3.js without polling

I've made a user interface in JavaScript with web3.js where the user can select an account to use. The accounts are displayed together with their current balance for convenience. I load the account ...
6
votes
1answer
1k views

Adding Wallet using web3.eth.accounts.wallet.add

On web3 0.20.1, I am using Infura to deploy a contract to Rinkeby. This probably requires me to add a wallet to web3.accounts to provide the gas needed. When I ran the following nodejs code, Web3 = ...
-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....
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
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(...
6
votes
2answers
2k views

getData() is not working

I want to call a function of the contract, something like this - module.exports.transfer = function(to,value,){ return token.methods.transfer.getData(to, value); } But I am facing the error ...
1
vote
1answer
678 views

Interact with MetaMask via PHP

I can easily interact with metamask via web3 js like this (JS): web3 = new Web3(web3.currentProvider); Is it possible to interact with metamask via php? For example (PHP): $ethereum = new Ethereum('...
1
vote
1answer
59 views

eth-crypto: How can I use the library in the browser?

Has anyone manage to use eth-crypto in the browser? I tried to use browserify but I failed. Any hints, what to do? EDIT: This is what I did (node:10.15.1/npm:6.4.1) 1) Installed eth-crypto (v1.3.2))...
0
votes
1answer
637 views

Get the list of pending transactions with Web3 for the given address/wallet

I'm trying to get information whether there are pending transactions for the given address. My code is as follows: web3.eth.getTransactionCount(‘ADDRESS’, ‘pending’, function(error, result){ if(!...
2
votes
1answer
268 views

How can I use solc solidity compiler on truffle webpack?

When I try to import solc, it raises an error which says: ERROR in ./~/require-from-string/index.js Module not found: Error: Can't resolve 'module' in 'C:\users\bisrat\Desktop\webpacksample\...