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
14
votes
4answers
17k views

unable to connect Ethereum node even RPC port: 8545 is open

I have created my private Ethereum blockchain network. From different servers I am able to connected and added into the network as peer without any problem. The way I run my server: geth --...
13
votes
2answers
6k views

What is msg.data?

Is msg.data equal to {from: addr1, data:something}? How to handle the data 'something'? when execution this code: web3.eth.sendTransaction({from: ..., to: addressOfE, data: something}); how to ...
12
votes
3answers
1k views

is there an easy way to get the full state of a contract?

I'm developing a quite complex contract with many state variables of all kinds. (mappings, arrays, uint, strings, bytes, etc). For testing, it would be very useful to get a JSON (or similar) with the ...
11
votes
1answer
6k views

How can I verify a signature with the web3 javascript API?

Using the javascript web3 API I can create a signature like this: > web3.eth.sign(eth.coinbase, "0xdeadbeef") "...
7
votes
2answers
714 views

Why does sendSignedTransaction return a tx hash BUT does not post to the Rinkeby network (React, Metamask, web3, infura)

I'm developing a very simple React application wherein a user clicks a button and some ether gets sent from one account to another. Currently, the onClick sendEther function crafts a proper signed ...
6
votes
3answers
4k views

How to list ALL Ethereum addresses with a positive balance

Using web3 I can query the balance of any fixed account with web3.eth.getBalance. Assuming I have the entire blockchain downloaded, how can I recover the list of all addresses that have a positive ...
25
votes
6answers
22k views

web3.eth.contract is not a function when making contract

Whenever I try and make a contract, I get: web3.eth.contract is not a function I'm using this code: const path = require('path'); const fs = require('fs'); const solc = require('solc'); ...
13
votes
2answers
6k views

Convert with JS a Solidity bytes32 to a Solidity string

I have functions which are forced to return a bytes32 object, but then in my webapp I need to reconvert them to a classic string. How can I do that?
10
votes
2answers
17k views

How to convert BigNumber to Number in Truffle framework?

I have written an ERC20 token contract and deployed it in test network using truffle framework. When I check the token balance for an account using web3 it was giving the result in BigNumber when I ...
8
votes
1answer
2k views

Private chain: Extracting the “data” from an account?

I have initiated and mined a transaction between two accounts. I also included a data field in this transaction. This is just random hex data. Here is the command: eth.sendTransaction({from:...
13
votes
2answers
13k views

'authentication needed: password or unlock' Error when trying to call smart contract method via web3

I am trying to call the smart contract method (deployed on remote ethereum account) from my nodejs DAPP, and getting the following error- Error: authentication needed: password or unlock at ...
9
votes
1answer
2k views

Is it possible to call debug_traceTransaction from nodejs?

Following answer (https://ethereum.stackexchange.com/a/9437/4575) [ 1 ] guide us to call debug_trace through using geth: As documented in debug.traceTransaction(...), you can only access this API ...
8
votes
2answers
11k views

Getting ABI data for ERC20 tokens programatically with Web3 [duplicate]

I am just starting to dive into Web3. I am trying to display the various ERC20 token values for a given Ethereum Address. The pieces I need to do this are: Token Contract Address Token Contract ABI ...
6
votes
5answers
2k views

How to deploy contract to the Ropsten test-net using web3.js

I am newbie in solidity. I don't understand what steps I must do for deploy contract in the Ropsten test-net. This is my contract: pragma solidity ^0.4.15; import './ERC20.sol'; import './SafeMath....
2
votes
2answers
514 views

How can I program my DApp to tell my user that their action/transaction has been confirmed?

Take an example of a voting DApp. A user clicks on a vote button, then behind the scenes the transaction containing the vote gets mined on the blockchain. The DApp then wants to alert('You have ...
20
votes
4answers
11k views

Does Web3.js have the functionality to create new accounts and unlock an account for a period of time for a series of transactions?

I want to create new accounts through my Dapp web interface and unlock a specific account so that transactions can be processed. I didn't see it in the web3.js documentation so wonder if that's on the ...
7
votes
3answers
301 views

Method overloading conflicting with transaction object

In my contract there is a buy method with 1 argument being overloaded by a 2nd one with 2 arguments: function buy( uint id ) function buy( uint id, uint quantity ) Now I want to call the 1st method ...
7
votes
2answers
11k views

How to build a front end for dApp

I am studying about DApps and Ethereum. I did get the Solidity part but I am confused about the front-end apps. Is it possible that I use web framework like PHP Laravel/Rails for Frontend/Db ...
5
votes
1answer
660 views

How can i safely unlock an account and send transactions from a web application server using web3js?

I need a web application backend to be able to make transactions to a smart contract. In order to do this i need to send a transaction on behalf of an account that is authorized by our smart contract. ...
5
votes
1answer
2k views

Making web3.js work from node server code

I'm running a geth node on the testnet and trying to run web3.js method from my node server code. var coinbase = web3.eth.coinbase; console.log(coinbase); However, I'm getting a provider not set or ...
4
votes
1answer
515 views

How to get byte code from deployed contract in

I want to get the byte code of a deployed contract. How can I get it? Is there a special function in web3.js? I haven't found any.
4
votes
3answers
2k views

How to use metamask for etheruem dapp

I am trying to create an application using ethereum ,where node.js has used to call methods of smart contract and angular as frontend . I want to use the metamask wallet so my apication can ...
3
votes
2answers
4k views

web3.accounts.create() is not a function

I want to create a new account via code (Node.js), so I ran the following code, which was copy-pasted from the docs: web3.eth.accounts.create(); How ever accounts' value is an empty array, and ...
3
votes
2answers
4k views

With web3 how would I get transaction AND function result?

I'm using testrpc, truffle, and web3 in Node. I've written my contract and pushed it to testrpc with truffle. Here's the gist of the Node code I have so far: let fs = require('fs'); let Web3 = ...
3
votes
1answer
2k views

How to properly set nonce in a web3 contract invocation?

I have this code, which works: MyToken.airdrop(wallets,amounts,{ gas: 1267051, gasPrice: 2000000000, },function(err,tx){ console.log('err is %s',err) console.log('tx is %s',tx) callback(err,...
1
vote
2answers
5k views

How to login with web3 without MetaMask?

Is it possible to sign a user in web3 without MetaMask? I am trying to execute a smart contract I created and I'm using Infura to connect to the Kovan test network, but web3.eth.accounts[0] is ...
0
votes
1answer
1k views

Check for error in transaction with web3js

If you look at this transaction in etherscan.io you can see that it notes that the transaction has an error Warning! Error encountered during contract execution [Bad instruction]. Same status can be ...
0
votes
3answers
1k views

Can I mine on my private blockchain using geth with rpc?

I am using the web3 api and want to try out mining using rpc. The usual miner.start() (which is used on terminal) does not work even after including the miner api when starting geth and I get the ...
8
votes
5answers
15k views

why did it returned null after call miner.start()

> miner.start() > null before it , I had created a account like this . user1 = eth.accounts[0] "0xb62f0bae52d153365661c4e23ab1d594484e9bef"
7
votes
2answers
8k views

Calling public array of structs using web3

Good day. I've got an array of structs such as: User[] public users; struct User{ uint idNum; string name; address userAddress; } And I'm trying to get the array of users with web3.js ...
6
votes
3answers
3k views

web3 methods not implemented

I'm running a geth node on the testnet and trying to run web3.js method from my node server code. Here's my code var Web3 = require("web3"); var web3 = new Web3(new Web3.providers.HttpProvider('http:...
5
votes
1answer
2k views

Get transaction id after contract function call

I'm using truffle. How can I get transaction id before it is mined? For example: contract.purchase(price).then(function(tx) { console.log("Success"); }).catch(function(e){ console.log(e); }...
4
votes
3answers
2k views

address.transfer not working

pragma solidity ^0.4.23; contract ApprovalContract { address public sender; address public receiver; address public constant approver = 0x5AEDA56215b167893e80B4fE645BA6d5Bab767DE; constructor() ...
4
votes
3answers
2k views

How do I determine whether the transaction is used for the contract creation?

I want to monitor Ethereum and memorise every contract published on the blockchain (basically the same thing that Etherscan does). How it is possible to do this using NodeJS & web3? How can I ...
3
votes
1answer
840 views

How to query token transfers like etherscan.io?

Look at this. We are able to see tx, from, to, value etc... How is etherscan achieving this? I badly need this kind of functionality in my app. How can I list token transfers for a ERC20 contract? ...
3
votes
1answer
2k views

How to sign a send method in web3 1.0?

I have the following function and don't want to manually sign the transaction every time it's called, how would I go about setting up a way of signing this transaction with an object. I've seen ...
3
votes
1answer
629 views

How to get byte32 similar data and return same index as ethereum wallet in web3.js?

Solidity byte32 return different value in web3, remix browser compiler and ethereum wallet In the contract, I have just added byte32 values and return it but in the web3 api, remix browser compiler ...
2
votes
3answers
2k views

for using web3.js it is necessary to install geth into your system

for using web3.js it is necessary to install geth into your system or it automatically connect with geth or ethereum blockchain? var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:...
1
vote
1answer
5k views

Using web3.eth.filter

The following link describes some of how the function web3.eth.filter(...) works: https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethfilter What I would like to do is get a list of the ...
1
vote
2answers
769 views

Image attached to Ethereum contract (off-chain)

What I am trying to do is make some smart contracts that I am going to sell to my clients giving them ownership of those contracts. A web service using web3 will be available to retrieve some ...
1
vote
1answer
4k views

Error: Returned error: insufficient funds for gas * price + value

Im using this code to send payment from Address A to address B.. But im getting this error always. (node:18492) UnhandledPromiseRejectionWarning: Error: Returned error: insufficient funds for gas * ...
1
vote
2answers
279 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 ...
1
vote
2answers
1k views

how to call contract method using sendRawTransaction

const privateKeyStr = ""; const privateKey = new Buffer(privateKeyStr, 'hex'); const contractAddress = '0x'; const COO = '0x'; let contractAddress = '0x'; let myContract = ...; //some other articles ...
6
votes
1answer
2k views

Understanding web3.eth.filter parameters

I have been looking through that web3.eth.filter function, and ran into a bit of a wall: var options = { fromBlock: "pending", toBlock: "latest", address: "...
6
votes
1answer
1k views

How can i setup a web3 webservice that listens for events from my smart contract?

I have a smart contract that broadcasts events to web3 clients, upon each event being broadcast, the listening client makes a tx call to my contract. I would like to set up an 'always on' event ...
5
votes
1answer
910 views

Can you add input data with a token transfer?

I was successfully able to send eth with some message here: 0x4ea3d0ae060aeb08f41fb8ff3e468b7e44092a251ccef118b386136fe6427a64 (little tackier though). I did this from MEW, but saw that it is not ...
4
votes
1answer
570 views

Reading a uint from a mapping keeps returning a random address

I am new to Solidity. I am facing an issue in a simple operation of storing and retrieving data from mapping (uint=> address). I have defined a simple contract: contract test { mapping (uint =&...
4
votes
1answer
675 views

How to get the transaction hash once it is mined?

In JavaScript (web3.js), how do I get the transaction-hash corresponding to a function executed in my smart contract?
3
votes
2answers
244 views

How to invoke a contract function in the future (under 10 blocks)

This is not a duplicate question, as the alarm contract only allows function calls to be made in the future, over a period of at least 10+ blocks... The current thinking is to just use the alarm ...
2
votes
1answer
398 views

Cannot connect to any ethereum networks using API key

I followed a tutorial about how to connect web3 with ethereum networks. I registered in infura.io and get all the urls. But when I try to connect to any network it is not connecting.When I print web3 ...