Questions tagged [javascript]

JavaScript is a dynamic, weakly-typed language used for client-side as well as server-side scripting.

Filter by
Sorted by
Tagged with
84
votes
12answers
33k views

Common useful JavaScript snippets for geth

In geth you can loadscript any .js file. I discovered this one on the wiki which I like a lot: function checkAllBalances() { var i =0; eth.accounts.forEach( function(e){ console.log(" eth....
36
votes
6answers
17k 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 ...
11
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 ...
25
votes
3answers
9k views

How does Solidity's sha3 / keccak256 hash uints?

This is not a question about the issue with Ethereum using a non-standard sha3. I have found the right JS hashing library, and am able to get matching hashes in JS and Solidity on byte strings. What I ...
4
votes
2answers
3k views

How do I print my account balances and TheDAO tokens from geth

Is there a convenient script to print out my account balances and TheDAO tokens from the go-ethereum client geth?
15
votes
6answers
21k views

Better pattern to detect web3 default account when using metamask

Context: I want to use blockies to render an identicon on the page, i get the defaultAccount from web3, for this, the user has to be logged on to metamask with a selected address from his wallet. The ...
28
votes
4answers
24k 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 ...
15
votes
6answers
12k 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?
5
votes
1answer
2k views

Listing transactions in a private blockchain?

In a private blockchain, is it possible to list the transactions based on from and to parameters in a transaction. Is it possible to check the latest transaction from or to an address? Also, is it ...
0
votes
0answers
316 views

(NEW UPDATE: I need to run “testrpc”) Signing a message using “ethereumjs-abi”? (Error: Invalid JSON RPC response: “”)

I am trying to sign a message using following JavaScript code (from HERE) function constructPaymentMessage(contractAddress, amount) { return ethereumjs.ABI.soliditySHA3( ["address", "uint256"], ...
8
votes
3answers
2k views

How to use bignumbers in truffle tests?

I am testing a smartcontract with Truffle V5. All works well if I do not use all decimals. If I set 18 decimals all explodes. The test code is this (from truffle docs): const MetaCoin = artifacts....
6
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 ...
0
votes
1answer
62 views

How to create an interaction between a smart contract and a HTML file with Node-js?

My Truffle project is this contract that just shows Yerevan is love: pragma solidity ^0.5.12; contract TEST{ string public note="Yerevan is love"; function rep() public view returns(string memory){ ...
7
votes
1answer
1k views

Event result parameters and arguments in console

I read about using events from this source http://solidity.readthedocs.io/en/latest/contracts.html#events I used a simple multiply contract: contract test1{ uint a; event event_res(string msg,...
21
votes
5answers
18k views

How to listen for contract events in JavaScript tests?

I'm trying to trigger events in my solidity contract to output some debug information in my javascript tests. However the events seem to get never caught. That's the relevant contract code: pragma ...
15
votes
5answers
11k views

web3.js with promisified API

I'd like to take away the pain from web3 development callback hell and use Promise pattern and async/await keywords on both client side and on Node.js. Do there exist any web3.js builds or forks that ...
13
votes
4answers
6k views

How to open the JavaScript console on Parity?

There is nothing like parity console. How to open the JavaScript console on Parity?
7
votes
2answers
4k views

How can I run scripted geth commands with specified command line parameters?

I have a contract running on the testnet, and every time I need to call a function, after opening Geth I have to type (or paste): primary = eth.accounts[0]; personal.unlockAccount(primary, '...
28
votes
7answers
28k 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
15k views

How do Enums work?

I am just starting out with Solidity and JavaScript and am trying to understand Enums. I have a simple contract pragma solidity ^0.4.4; contract SimpleEnum { enum SomeData {Channel} SomeData ...
7
votes
1answer
5k views

JavaScript Code Required to Generate an Ethereum Address?

I am aware of several tools and websites that generate addresses for you, but I'm looking for an actual JavaScript code snippet to demonstrate the steps plainly.
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 ...
7
votes
2answers
11k views

Can someone explain 'signing a transaction' and how its different from sending ether?

Some times when using meta mask or other contracts, instead of sending an amount, I simply sign the transaction. see here Say I want a function() that renames a string. function string(string ...
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:...
6
votes
1answer
1k views

Is there any lightweight JS library that generates Ethereum addresses from 256-bit private keys?

I have a 256-bit private key and I want to get its public address without having to install Geth (which is quite heavy) on the machine. Is there any small JS lib that does that?
5
votes
1answer
114 views

Getting event history takes a really long time or doesn't work at all

I'm having trouble getting a history of events. I'm unsure if I am misunderstanding how events work, if I'm coding wrong, or if it has anything to do with the recent Ethereum attacks slowing down the ...
3
votes
1answer
295 views

Geth - reading public address[] from contract

After setting up testrpc and attaching geth: testrpc -a 10 geth attach rpc:http://localhost:8545 I initialise the following contract on the geth command line: pragma solidity ^0.4.6; contract ...
4
votes
1answer
731 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?
2
votes
2answers
2k views

Web3.js browser version only

I want to create a simple page to interact with my deployed contract. I don't want to use Node.js. I want to use html + web3.js browser version. I got a link: https://github.com/ethereum/web3.js/tree/...
1
vote
2answers
662 views

how to customize my own commands in geth console?

How to customize my own commands in geth console? We know that in geth console, we can type eth.accounts and other commands. I found that there is a JavaScript parser/interpreter named Otto which ...
1
vote
2answers
506 views

javascript local sign and sendRawTransaction to remote node

In order to use Web3 provided by MyEtherAPI, I need to locally sign a transaction, since myetherapi supports only eth_sendRawTransaction. I found a good source to do so on github, unfortunately it ...
1
vote
1answer
402 views

How to bundle own web3 version and using Metamask

I am a bit of a javascript noob and have some questions about using web3js and Metamask. My objective (for now) is to display the ether balance as displayed on my Metamask (where I am logged in). ...
0
votes
1answer
632 views

“Updated :” How to see “output” of “web3.personal.sign” in “browser”? (“Method personal_sign not supported”)

Note: I updated the html / JavaScript code according to the answer and I used THIS META MASK sample code for web3 provider. However, I receive the same error. I eventually did not understand that do I ...
2
votes
1answer
8k views

How to make transactions using private key in web3? [duplicate]

I have account private key, contract address and abi and I need to call contract function with this account. Is it possible?
7
votes
1answer
4k views

Executing custom JavaScript Snippets through Non-Interactive console (geth --exec)

I have a JavaScript snippet to get the latest transaction to/from an account. After starting the geth instance, I did this in the interactive JS console: jsFunction is a function in filename.js &...
5
votes
2answers
689 views

Make data from smartcontracts / events only visible for certain address/users

I Have an use case where i need : 1- My data not to be visible to the public. 2- To be able to revoke my clients/users rights to view said data from my smart contract. As anyone done that before ? ...
1
vote
2answers
3k views

encode data input of the raw transaction to update an contract function? [duplicate]

I need to update a contract by calling one of their function but I cant use web3.js so I need to send a raw transaction. example of function to be call on the contract: test(address buyer, uint256 ...
1
vote
1answer
3k views

How to map a web3 to a react.js state

How would you map a changing variable from web3 to react.js component? Example: class App extends Component { constructor(props){ super(props); this.state = { blockNumber: web3.eth....
10
votes
2answers
1k views

Programmatically saving the contract address of a submitted contract

I understand how the below web3js code block works, adapted from here: https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethcontract But how does one save the contract address ...
4
votes
1answer
2k views

Transaction gas cost in truffle test case

Below is from a truffle test cases in javascript, where I was trying to add the gas cost to an account balance to confirm the sum of transaction, where the sum should be equal to the previous balance. ...
1
vote
3answers
6k views

How to generate Private key, public key and address

I can't find any documentation online about doing this in Javascript other than this. I want to know how does authentication work in a ethereum dApp's.. As per my understanding user seed somehow gets ...
8
votes
2answers
7k views

How do you get the balance of an account using truffle/ether-pudding?

Is there an ether-pudding way to get the balance of a contract/account, or should I just use web3.eth.getBalance(account)?
8
votes
1answer
3k views

How to connect NodeJS to the Ethereum network?

I have Mist wallet running on Windows 8. I want to connect my NodeJS applcation to the Ethereum network. I have no idea where to start. Could you point me to the direction I should be looking at? Are ...
7
votes
1answer
2k views

How to use the testrpc `evm_increaseTime` parameter from truffle console? [duplicate]

I am creating smart contracts with truffle and testrpc. When writing unit tests I wish to change the block time to simulate different times that smart contracts may be called. How does one set ...
7
votes
5answers
13k 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": ...
7
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
1answer
2k views

Is there a Javascript client for Ethereum, like Geth?

Ethereum's Github has ethereumjs-lib. It appears to be a collection of modules, but is it also a client like Geth? If so, how can one run this Javascript client?
5
votes
1answer
916 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 ...
4
votes
0answers
354 views

How to Catch Connection Issues to Web3 Provider using Web3.js

My node.js script is able to successfully connect to the Web3 provider when both the private key (using truffle-privatekey-provider) and the provider host URL are correct. let privateKey = ..., ...
4
votes
1answer
5k views

How to use miner.start(2) from javascript

Refering to "Common useful JavaScript snippets for geth" Got Following example to run miner from javascript: Mine only when there are transactions! var mining_threads = 1 function ...