The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
8
votes
2answers
2k views

How do I know if a submitted block became an uncle?

We need to detect that the submitted work became an uncle. How would I do this with geth api? I thought of checking the submitted block number later for any uncles that match my block's hash. Is there ...
7
votes
2answers
4k views

Do I have to unlock my account in geth to call a web3.eth.sign() in JavaScript?

I have: A geth account Access to web3 API I want to: Invoke the function, web3.eth.sign(coinbase, sha) If I put this in a javascript file sign.js, and I call node.js, will it sign my message? Or ...
6
votes
3answers
3k views

Is there any API for sending and receiving Ethers?

Is there any API for send and receive Ethers? If not, i am trying to use web3.js in my own server; What are the technical implications? Major security concerns? Can I use the same API for creating ...
5
votes
1answer
971 views

What's the difference in the ways of calling a contract function?

After I get an instance of a contract, there are 3 ways to call the contract function below: 1.testInstance.testfunc({from:eth.accounts[0]}) 2.testInstance.testfunc.sendTransaction({from:eth.accounts[...
5
votes
3answers
3k views

What is the MetaMask workaround if Web3 is deprecated

While using MetaMask, adding Web3 to a Javascript program displays the following message in the Chrome console: "MetaMask: web3 will be deprecated in the near future in favor of the ethereumProvider" ...
5
votes
2answers
1k views

How to access Geth's state trie

Using Geth, how can I extract a snapshot of the network state for a given block? My Geth node runs a full sync (~300 gb) which means the state trie should already be saved down. I've tried accessing ...
5
votes
1answer
3k views

Solidity/Web3.js Cannot send value to non-payable constructor

I have a simple contract that I built a small webapplication with. The contract is as follows: contract MyContract { address public creator; function MyContract() { creator = msg....
5
votes
2answers
4k views

How does MetaMask inject Web3?

I'm just getting started with Solidity and Truffle, and I'm quite confused regarding this example code: App = { web3Provider: null, contracts: {}, ... initWeb3: function() { // Is there an ...
4
votes
2answers
1k views

Watching for changes in web3.isConnected()

I am using Meteor & Web3 to talk to a Geth node, and would like to have an event fire in web3 when the Geth node goes down. Web3 has the ability to add callbacks to web3.eth.isSyncing to detect ...
4
votes
1answer
709 views

Exposing Geth to Hybrid mobile app

I'm making a Hybrid mobile app and planning to use web3.js to access Geth. What's the best way to expose Geth to the hybrid mobile app? I will be running Geth on ubuntu 14.04 on Aws
4
votes
4answers
462 views

Truffle Drizzle-box fails with TypeError: (0 , _drizzle.generateContractsInitialState) is not a function

Right after unboxing Drizzle-box I'm getting a TypeError: (0 , _drizzle.generateContractsInitialState) is not a function. Ganache is running on localhost:8545, contracts are deployed, Metamask ...
3
votes
1answer
4k views

Web3 - Uncaught TypeError: contract.abi.filter is not a function

I have compiled and deployed a simple Hello World contract using truffle: pragma solidity ^0.4.4; contract Greeter { function Greeter() { } function sayHello() returns(string) { ...
3
votes
1answer
2k views

Is it possible to use web3.js API methods to interact with a contract deployed on Rinkeby?

I have deployed a simple HelloWorld Solidity contract on one of the Ethereum Testnet called Rinkeby with MyEtherWallet and of-course I can interact with it. Now I want to interact with that contract ...
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
1answer
3k views

Get history of transactions to specific account [duplicate]

I am using web3.js and geth to do my coding. I have an Ether Account (Not a Wallet Contract) that will be receiving funds from clients. The clients will be writing a number in the DATA field (that you ...
2
votes
1answer
1k views

Ethereum Web3 Asynchronous Calls/Promises/Callbacks [closed]

I'm a newcomer to Ethereum, working on a project that requires a certain piece of data from a contract, in order to populate a list in my HTML frontend. However, as you might expect, the calls to the ...
2
votes
2answers
2k views

Retrieve data from smart contract using sendTransaction

Lets take a very basic smart contract that has one function in which you send a number and it will return the square. It has another function that returns a fixed string. contract MyContract { uint ...
2
votes
2answers
5k views

Send wei to payable function with web3 async

I want to send 100wei to a payable function in my deployed contract. But i don't want to sign the transaction because of to much effort to get this going. I just want to submit the transaction with ...
2
votes
1answer
655 views

Error: invalid argument 0: json: cannot unmarshal object into Go value of type string

I have followed following solution. When I try to do shh.getPrivateKey(kId).then(console.log) I have received following error, please note that this line works under web3.py: ...
1
vote
2answers
1k views

web3: TypeError: 'toBytes' is not a function

The way I install web3: npm install -g web3 The way I connect into web3: Web3 = require("web3"); web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); if(!web3.isConnected()){ ...
0
votes
1answer
140 views

How to send ERC20 Token?

I try to send Token based on Erc20. and I can send Ether and something function but i dont know how to use transfer function in javascript like that. function transfer(address _to, uint256 _value) ...
12
votes
5answers
8k views

Getting Uncaught Error: new BigNumber() not a number: [object Object]

I am quite new to this. Please help me out. I am trying to build a dapp using meteor. I am having a little trouble with calling a function of the contract using web3. Here's the code snippet that's ...
8
votes
2answers
928 views

Fallback function in web3

I find answer how to make upgradable contract here How to call function from currentVersion with fallback function on web3? contract Relay { address public currentVersion; address ...
8
votes
2answers
2k views

contract event not firing in web3 node console

It appears my events are not being fired in my node application when I transact the contract in the ethereum wallet gui. I deployed a custom contract via ethereum-wallet I have fired up geth attach ...
7
votes
1answer
596 views

Is there a recommended / secure way to unlock an account through Web3 interface / HTML page securely?

This question was asked on Reddit: Is there a secure/recommended solution to unlock an account and send a tx through the Web3 interface (from a Html page)? One of the alternatives that I have ...
7
votes
1answer
16k views

Using web3.eth.estimateGas cause “gas required exceeds allowance or always failing transaction”

In solidity code I have function addPhase and it works well. The code below also works well for (let j = 0; j < companies[i].phases.length; j++) { transactions.push( this.contract....
7
votes
1answer
9k views

How to get string from hex on Smart Contracts results [duplicate]

On a Smart Contract called "mem" there is a function called "get()" that returns a bytes32 that is supposed to be a string. How can I decode the string? The result is an hex value. I have tried ...
6
votes
1answer
533 views

Gas estimation for mapping updating with web3js

The gas estimation for contract deploying with web3js will look like: var res = web3.eth.estimateGas({ from: web3.eth.defaultAccount, data: contractByteCode }); For example, I have the ...
6
votes
2answers
1k views

How to access all accounts across multiple nodes? JS/Web3.js/API

I'm running a private ethereum development network with 3 nodes connected to each other. Before asking my question, something about my setup. This is how I start those nodes: geth --networkid 2345 --...
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 ...
6
votes
4answers
10k views

How to get value of a contract public property using web3.eth

using web3 javascript library how do you get the current value of a public property. e.g. contract MyContract { address public owner; ... } Here's a snippet of the abi: [{ "constant": ...
5
votes
2answers
3k views

Getting Go-Ethereum current network id

How can I know the network id, with web3 or command line, so I know to which network my geth has attached?
5
votes
2answers
5k views

passing String object with “0x..” value as bytes32 to a solidity function

I'm having trouble to pass bytes32 to a solidity function from javascript. It's converting to an incorrect bytes32 in solidity. The javascript is a test, running with truffle v3.3.1 on testRPC v3.0.5....
5
votes
2answers
6k views

How to obtain all transaction of a contract?

I'm trying to obtain the all transactions of a contract, but in all cases i only obtained [] or undefined. I'm following this posts: Common useful JavaScript snippets for geth web3 filter option not ...
5
votes
1answer
859 views

Transaction w/ invalid nonce

Web3.js throws an error "Transaction w/ invalid nonce." when I try to call contract methods from JavaScript console. The same methods from the same contracts work fine from Mist, or, what is strange ...
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/...
5
votes
1answer
4k views

Provided address is invalid, the capitalization checksum test failed, or its an indrect IBAN address which can't be converted

Here is my transaction from ethereum. transaction is shown as followed { blockNumber:12, contractAddress:null, cumulativeGasUsed:22977, gasUsed:22977, status:1, ...
4
votes
1answer
2k views

Manually set web3 version in truffle?

The version of web3 in Truffle v4.0.5 is v0.20.3. Is it possible to manually upgrade the web3 version? Similar to this question about web3 in geth. (It's hardcoded.) Somewhat relevant to this issue.
4
votes
2answers
2k views

Web3js - “The returned value is not a convertible string”

Can someone please help me. While trying to invoke a constant function which returns string, I am getting "Promise RejectedError: ERROR: The returned value is not a convertible string:" ...
4
votes
1answer
255 views

Is it possible to check which RPC APIs are available?

Is it possible for a decentralized application to get details about the offered JSON-RPC APIs from the local ethereum node? I want to check the following specs in the following order using web3.js: ...
4
votes
2answers
458 views

Web3 Javascript API — Transaction Object Not Matching Documentation

Noob question about the Web3 Javascript API. When I use web3.eth.getTransaction(), the object that comes back has some properties that I cannot seem to find in the documentation. For example, here is ...
4
votes
2answers
746 views

Contract not deploying on blockchain using solc & web3

I am using the npm package of solc to compile the contracts and accessing it as given here. It is compiling my contracts. But when I try to deploy the contract using web3.eth.sendTransaction({data: ...
4
votes
1answer
2k views

Is there a way in web3 to get a transaction by address and nonce?

I know I can get the current nonce using eth.getTransactionCount(address), but I'm looking for something like eth.getTransaction(address, nonce) (for arbitrary nonce), similarly to eth....
4
votes
1answer
4k views

Are contract calls asynchronous in web3.js?

Suppose we have a contract: contract C { uint256 a; uint256 b; function setA(uint256 aval) { a = aval; } function setB(uint256 bval) { b = bval; } ...
4
votes
1answer
2k views

Accessing mapping inside object with web3.js

Good day. I have a struct object called HomeWork HomeWork[] public homeworks; struct HomeWork{ uint256 assignId; string description; mapping(address=>uint256)handedAt; mapping(...
3
votes
1answer
2k views

get the return value of payable function?

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({ ...
3
votes
1answer
757 views

How to read responses from calls to contract methods made using web3.js?

I have built a contract which provides a simple method for storing some data in a property of my contract on the blockchain. I can interface with my contract using web3.js and I have no issue doing ...
3
votes
1answer
2k views

How to trigger contract fallback function from Javascript

For a simple contract: pragma solidity ^0.4.11; contract Test { uint private val; function getVal() constant returns(uint) { return val; } function setVal(uint newVal) payable { ...
3
votes
1answer
742 views

How to decrypt an encrypted message using metamask?

I have a message encrypted with the public key. Metamask has its corresponding private key (account). How can I decrypt it with the metamask? Does metamask provide such feature? What I meant is just ...
3
votes
1answer
339 views

web3.js: Error: The method shh_newSymKey does not exist/is not available on Web3.js

My main goal is to call web3.shh functions using RPC API , Web3.py or Web3.js. I can call web3.shh functions when I use geth attach; which is my last option to do. I am following this answer. geth ...