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

140
votes
2answers
26k views

What is the difference between a transaction and a call?

What is the difference between a transaction and a call? In some interfaces, I can interact with contracts via calls or via transactions. What is the difference between the two, and can contracts also ...
44
votes
8answers
21k views

How to get contract internal transactions

I'd like to get the contract internal transactions like: https://etherscan.io/address/0xd654bdd32fc99471455e86c2e7f7d7b6437e9179#internaltx I'm using web3 API. Is there any way to do it? Where do ...
18
votes
3answers
22k views

How to get return values when function with argument is called?

I am writing below a simple contract which stores all results of questionnaires for each ID. contract answer{ mapping(address => mapping(string => bool)) voters; struct qList { uint ...
15
votes
2answers
2k views

How do I retrieve the Voted events from TheDAO?

This question was asked by @Pablo Yabo in the comment section of the question How can I view The DAO proposals including the current voting status?.
25
votes
3answers
12k views

What are the limitations to estimateGas and when would its estimate be considerably wrong?

web3.eth.estimateGas and JSON-RPC estimateGas can be used to see how much gas should be specified for a transaction, before crafting the transaction. Since it is an estimate, are there any ...
28
votes
4answers
3k views

How can a DApp detect a fork or chain reorganization using web3.js or additional libraries?

Take an example of a voting DApp. A user clicks on a vote button, then behind the scenes a transaction gets mined on the blockchain, and finally the DApp tells the user their vote has been recorded. ...
14
votes
4answers
7k views

Infura web3 provider for Events (.get & .watch)

I am using infura for connecting to testnet/mainnet as my server side web3 provider. This works for most requests and operations, but it does not seem to work for Events. const allEvents = (event, ...
27
votes
6answers
14k views

ecrecover from Geth and web3.eth.sign

I have tried to use ecrecover() to verify the signature of a message. I have looked at lots of references here and elsewhere, like: https://lab-blog.ey.com/2016/12/19/ecrecover/ How does one ...
21
votes
4answers
29k views

How to call my contract's function using sendTransaction

This may be a very basic question, I don't know why but I am unable to find correct solution to how can I call my contract's method using sendTransaction. I have a transfer(address, uint256) function ...
30
votes
6answers
13k views

How do I parse the transaction receipt log with web3.js?

The event parser in web3 provides a nice parsing functionality for events, and I use it for logging all events to a file, but it's very difficult to use for looking at individual events for a ...
13
votes
2answers
3k views

Can a contract listen to events of another contract?

I read that to listen to events you need to use web3.js. Are there other ways of doing it? Can a contract even somehow listen to events of another contract? Thanks!
4
votes
3answers
6k views

Invalid JSON RPC response error for sendTransaction on Infura + Ropsten node + Truffle console

Calls work but transactions throw the error - Error: Invalid JSON RPC response: "" I am using web3 v0.19.0 & Truffle v3.4.9. Deploying contract using truffle, truffle migrate --network ...
17
votes
3answers
4k views

How to programmatically detect and accept ETH and ERC20 deposits

I'm looking to replicate the functionality provided by cryptocurrency exchanges such as Kraken and Poloniex when it comes to depositing ETH and tokens. Namely: Users can generate and send funds to ...
5
votes
3answers
14k views

How to properly create a raw transaction and sign it using web3 in browser

I want to create and sign a transaction in browser using web3. In order to create a raw transaction, I think I have to do something like this (hopefully you can fill the gaps of my knowledge) var pk =...
21
votes
1answer
2k views

What are effective techniques to encrypt/decrypt data stored in a smart contract?

Rather than sending and storing plain text in a smart contract, the use case objective is to encrypt first and then subsequently access the data and decrypt at the point of use. What is the most ...
10
votes
1answer
3k views

Can I unlock an account using JSON-RPC?

The only way I can work with ETH is through --rpc mode. Normally I would prefer to use the Python interface. But I found myself in a situation where the RPC is very limited. For example, I can't ...
9
votes
1answer
2k views

Does Solidity's constant keyword do anything?

It seems that the purpose of function foo() constant {} is to indicate that a function does not change the contract's state. And yet, as it states here, the compiler doesn't actually enforce this. So ...
28
votes
1answer
9k views

What are event topics?

I know that indexed arguments index the values for those arguments so that filtering will be faster. But what are topics? And what are they used for? I know that signature of an event is a topic. ...
19
votes
1answer
6k views

What are *C*, *E* and *S* properties in message call return object?

(JS) var contract = web3.eth.contract(abiDefinition).at(address); contract.test(value, gotResult); function gotResult(error, result) { if(!error) { console.log(...
24
votes
2answers
2k views

Is it a good practice to log an event every time I throw in Solidity?

In Solidity (0.3.2) I am aware that there is no way to throw specific exceptions. (Everything is an invalid JUMP error.) It seems beneficial to have a way to log specific errors. Does it make sense to ...
23
votes
3answers
18k views

Returning a struct and reading via Web3

I am storing data in my contract using a mapping of structs. For examples sake, say I'm storing employee info (name/address/salary), mapped by their employee ID. Via a web front-end, I'd like to be ...
13
votes
1answer
1k views

How do I get the storage indices/keys?

I would like to explore the storage data of a contract. I have geth fully synched and I interact with it over RPC. There is the function "eth.getStorageAt(addr, index, block)" provided, but you need ...
8
votes
1answer
2k views

Iterating over all public values of a mapping in web3

Let's assume we have the standard token contract with balances: mapping (address => uint256) public balanceOf; If I want to know balances of all addresses (who have ever transacted with the ...
7
votes
2answers
2k views

Who gets the fee from contract call?

Basically you don't need to pay fee for contract call, but if a contract method does lots of work, you need to add gas in contract call to prevent DoS attack like this: contract.method.call({gas: ...
17
votes
3answers
24k views

Unlocking accounts and making transactions in web3.js

This question is related to this one and this one. It also has a partial answer here and here. In the third link the account is being unlocked for a period of time using web3.js: web3.personal....
10
votes
1answer
752 views

How can I reliably induce a blockchain fork for testing purposes?

I would like to reliably induce a fork on a private testnet so that I can test the behavior of off-blockchain code that interacts with contracts. (see related questions as to why I would want to do ...
28
votes
5answers
18k views

How to access the event log by knowing the contract address (web3)?

How can I access a log stored in one of the tx of the contract via web3? Code example: event newtest(string indexed name, uint indexed idlevel,string indexed multib, string objmulti, uint objnm); ...
23
votes
5answers
13k views

web3: How do I get past events of myContract.myEvent?

I use the following JS code to get notified of Solidity events and it works well for incoming new events: myContract.myEvent().watch((error, result) => { if (error) console.log('Error in ...
13
votes
5answers
26k views

Deploy contract from NodeJS using web3

I'm trying to create and deploy a smart contract through NodeJS using web3, but it is not working as I get a "web3.eth.contract.new is not a function". Here is my code: var web3 = require('ethereum....
18
votes
2answers
6k views

Why aren't Solidity sha3 hashes not matching what other sha3 libraries produce?

Solidity has a function named sha3 and I tested it with an empty string input. It is not matching what other sha3 libraries produce. I see contracts written by others using the same sha3 function ...
15
votes
6answers
11k views

Encoding/Decoding contract ABI data

How to encode and decode ABI data? Can someone show me an example with web3js library?
14
votes
5answers
4k views

How do I know when I've run out of gas programmatically?

This keeps coming up on the gitter forums so I thought I'd ask and answer this question: How do you know when you've run out of gas?
13
votes
4answers
2k views

Error: The contract code couldn't be stored, please check your gas amount

I am using the below code to create the contact it give the error: Error: The contract code couldn't be stored, please check your gas amount. Code: primaryAccount = web3.eth.accounts[0]; //...
11
votes
1answer
1k views

How to read a private variable from a contract?

Given a contract, how can I find out the current value of one of its variables (as a dev, not from the context of another contract), if it's not public?
14
votes
4answers
23k views

How to send ERC20 token using Web3 API?

I created some custom token in Ropsten testnet using this guide: https://steemit.com/ethereum/@maxnachamkin/how-to-create-your-own-ethereum-token-in-an-hour-erc20-verified I can send it to other ...
14
votes
3answers
3k views

Accessing past values of Smart Contract variables

I would like to know if is possible to inquiry variable values using older blocks. For example I have contract Simple { string32 message public; function Simple() { message = msg....
12
votes
5answers
8k views

Decode input data on transaction

I have an ABI and the input value of the transaction and want to know what function has been called on a contract and with what arguments (one or multiple of different types), preferably using geth, ...
12
votes
2answers
759 views

What is the way to make Ethereum available to users for free?

As the web is mostly free today (I mean the old web, the one < 3), most people won't agree in beeing asked for fuel to run sites, apps, even if the gain in terms of safety and trust are so much ...
23
votes
3answers
4k views

How to detect if an address is a contract?

I'm interested in knowing whether any particular address is a contract address or a standard address. There have been similar questions on the topic, but I'm not looking to detect whether an address ...
19
votes
2answers
10k views

Is there a way to find an account's current transaction nonce?

I need to know my transaction nonce because I am doing fancy stuff with contract addresses (which are the keccak hash of my address + my transaction nonce). Is there a way to find this through the ...
14
votes
1answer
4k views

Difference between transactions and raw transactions in web3.js

Reading the documentation of web3.js I have come across sending transactions and raw transactions.In the documentation it's specified that send raw transaction sends an already signed transaction. ...
12
votes
1answer
11k views

How to convert string to bytes32 in web3js?

I have a contract with a public variable that's bytes32. If I enter the value 20160528 then it auto converts to bytes32. Is there anyway to convert it back from the nodejs terminal? I've been ...
5
votes
1answer
2k views

How to update the web3 API version in geth?

I spent a couple of hours on upgrading web3 API to v0.15.3 in geth (on Mac OSX) with no effect. I installed the newest geth and it says: web3.version { api: "0.13.0", client: "Geth/v1.3.4/darwin/...
3
votes
1answer
484 views

I need help with signatures

So, for my studies, I am supposed to interact with a contract function that has the following built in condition: if (ecrecover(_h, _v, _r, _s) == msg.sender && _h == sha3(this)) I am ...
14
votes
6answers
10k views

How can dapps work on smartphones?

How can dapps on mobile web browsers interact with web3.js? Is there any tool like Metamask or Mist on the roadmap for mobile?
17
votes
3answers
15k views

error: replacement transaction underpriced

Im trying to send a raw transaction using web3 to ropsten testnet and Im getting this error: replacement transaction underpriced where sometimes my tx works and sometimes I get this error. my tx ...
13
votes
2answers
6k views

To which remote ethereum nodes does Metamask plugin send signed transactions? and are they exposed to denial of service attacks?

So Metamask allows in it UI to connect to different ethereum nw (public/ testnet) right. Do who is maintaining these peers? Can I trust these peers?. If so, can I setup similar service on my machine ...
17
votes
3answers
11k views

What does the Web3 “BigNumber not a base 16 number Error” mean

Is there a known problem with parsing events containing strings in Truffle/Web3? I'm using truffle with the following simple contract contract Board { string foo; event Shout(); event ...
4
votes
2answers
4k views

Private key needed or not for sending transaction in ethereum

In web3 APIs I could not see an option to specify private key for sending a transaction in doc. How this is done then ? My understanding is that we need private key of a particular account to send ...
11
votes
2answers
1k views

Can Solidity constant functions be arbitrarily complex?

Non-constant functions are limited in computational complexity by the block gas limit. I assume, but am not sure, that this does not apply to constant functions. Are constant functions in any way ...