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
180 votes
2 answers
49k 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 ...
user avatar
  • 7,226
70 votes
13 answers
50k 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 ...
user avatar
  • 2,503
29 votes
3 answers
33k views

How to get return values when a non view function 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 ...
user avatar
  • 415
30 votes
4 answers
52k 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 ...
user avatar
36 votes
6 answers
7k 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. ...
user avatar
  • 78.8k
27 votes
3 answers
9k 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 ...
user avatar
  • 421
16 votes
4 answers
10k 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, ...
user avatar
  • 2,286
16 votes
2 answers
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?.
user avatar
7 votes
3 answers
11k 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 ...
user avatar
  • 185
41 votes
3 answers
19k 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 ...
user avatar
  • 78.8k
33 votes
6 answers
26k 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 ...
user avatar
22 votes
2 answers
7k 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!
user avatar
42 votes
1 answer
25k views

What are Solidity events and how they are related to topics and logs?

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. ...
user avatar
29 votes
6 answers
59k 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 ...
user avatar
47 votes
6 answers
36k 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 ...
user avatar
  • 4,181
18 votes
4 answers
32k 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 =...
user avatar
22 votes
2 answers
4k 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 ...
user avatar
  • 1,605
19 votes
5 answers
32k 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, ...
user avatar
  • 861
7 votes
1 answer
10k views

Connecting the wallet of to your dApp and different Ethereum wallet types

How users can use connect their different wallets, like MetaMask, mobile wallets and hardware wallets with a dApp? What wallets are supported?
user avatar
11 votes
1 answer
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 ...
user avatar
  • 463
9 votes
1 answer
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 ...
user avatar
31 votes
5 answers
32k 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 ...
user avatar
  • 615
23 votes
1 answer
7k 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(...
user avatar
  • 4,168
1 vote
1 answer
500 views

Swap for tokens with Bot Protection Enabled (BpEnabled)

!!Apology in advance for such verbosity!! Background I came across this BEP20 token (0xcc7a91413769891de2e9ebbfc96d2eb1874b5760) which had sufficient Liquidity added at TGE but bot protection was ...
user avatar
27 votes
2 answers
3k 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 ...
user avatar
  • 3,440
4 votes
1 answer
1k views

How to build an Ethereum hot wallet for an exchange

I’m developing an exchange. When a new user register on website we will create new eth wallet for them. When they deposit USDT on their wallet how can I transfer that USDT amount to another address (...
user avatar
8 votes
2 answers
7k views

get the return value of payable function? [duplicate]

Let's say there's a payable Solidity function function doSomething() payable returns(uint) { require(msg.value == 1 ether); return 1; } And you call this function instance.doSomething({ ...
user avatar
36 votes
5 answers
34k 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 ...
user avatar
45 votes
5 answers
87k 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 ...
user avatar
11 votes
5 answers
16k views

How to verify MetaMask account holder is the real owner of the address?

I'm making a dapp that will make calls to a Node.js server. I expect the user to have MetaMask installed and I want to verify that he is the real owner of the current address on MetaMask (i.e. ...
user avatar
  • 336
26 votes
7 answers
45k 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....
user avatar
35 votes
5 answers
30k 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); ...
user avatar
  • 353
23 votes
7 answers
29k views

Encoding/Decoding contract ABI data

How to encode and decode ABI data? Can someone show me an example with web3js library?
user avatar
  • 733
19 votes
1 answer
3k 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 ...
user avatar
23 votes
2 answers
9k 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 ...
user avatar
  • 78.8k
21 votes
1 answer
4k 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?
user avatar
  • 1,015
14 votes
1 answer
2k 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 ...
user avatar
  • 4,181
9 votes
1 answer
3k 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 ...
user avatar
22 votes
4 answers
33k 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....
user avatar
  • 5,154
15 votes
2 answers
2k views

Can Solidity view/pure 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 view/pure functions. Are view/pure functions in any way ...
user avatar
  • 8,114
8 votes
2 answers
3k 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: ...
user avatar
6 votes
1 answer
3k 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/...
user avatar
  • 1,858
32 votes
6 answers
34k 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 ...
user avatar
  • 8,114
33 votes
5 answers
18k 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 ...
user avatar
  • 443
15 votes
5 answers
5k 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?
user avatar
  • 4,181
28 votes
1 answer
33k 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 ...
user avatar
  • 3,379
14 votes
5 answers
3k 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]; //...
user avatar
2 votes
1 answer
1k views

New Ethereum Account with Infura

Can I create a new ethereum account using Infura like we do using web3.personal.newAccount();
user avatar
31 votes
8 answers
74k views

How to get transactions by account using web3 js?

I'm sure this question was asked before, but I did not find any result that helped my problem. How can I get the transactions (in and out) for a given account? I use nodejs and web3? With this line ...
user avatar
37 votes
3 answers
41k views

How can I view event logs for an ethereum contract?

After reading the this post, it seems like I should be able to access the logs of events that have been called on an Ethereum contract. The section I am interested in is Option 3 which is using event ...
user avatar

1
2 3 4 5
13