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
82
votes
11answers
31k 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
15k 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 ...
35
votes
2answers
19k views

How does Lisk differ from Ethereum?

Lisk is going to be a full stack DApp development framework for building and distributing decentralized applications. It's currently in the crowdfunding stage but got also added to Microsofts ...
27
votes
7answers
24k 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'); ...
26
votes
4answers
19k 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 ...
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 ...
20
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
6answers
19k 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 ...
15
votes
6answers
11k 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?
14
votes
5answers
10k 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?
12
votes
2answers
14k 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 ...
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 ...
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 ...
10
votes
4answers
8k views

Web3.js Get Contract Abi Knowing Only Contract Address

is there a way with web3.js to get a contract abi json, knowing only the contract address? I cannot find anymore a link in wich they explain how to do this, in this post the guy replied telling that ...
9
votes
1answer
246 views

Why is web3 being proposed as a global variable in Mist? What's the reasoning?

I have heard that web3 is supposed to have global scope, something similar to document or window. What is the reasoning behind this architectural choice? Is this still an underlying assumption? In ...
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
2answers
10k 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 ...
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
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, '...
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 &...
7
votes
3answers
1k 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....
7
votes
1answer
144 views

How to connect AugurProject's ethrpc to a local testnet

I have GETH running a test network, and now I'd like to get AugurProject's ETHRPC to connect. I can't find any documentation on ETHRPC.
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.
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,...
6
votes
4answers
11k 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": ...
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
2answers
1k views

Can I pass arguments to a .js script on Geth?

I'm starting to get a handle of Geth, especially the scripts, following this and this. I have scripts that create contracts and call functions, but I don't know how to pass arguments to a script. ...
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?
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?
6
votes
1answer
132 views

Is that easy to turn a centralized app into a dApp hosted on Ethereum blockchain?

Currently I have an app that I use on my own servers. It is coded with JavaScript and PHP. The code is ready, I mean already exists. Would it be difficult to turn it into a dApp using smart-contracts,...
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
2answers
2k views

Execute contract function with raw transaction

I am trying to build a light interface which can broadcast a raw transaction and execute an Ethereum contract's function. While I am able to build a simple transaction there is little guidance on how ...
6
votes
1answer
294 views

Contract deployment without solidity online compiler

I am new to the dApp development. I want to deploy a contract to Ethereum through a website i am building. However i don't want the user to do it through the solidity online compiler or mist wallet. I ...
6
votes
1answer
414 views

Is truffle based on node and is it possible to run some kind of node debugger in order to pause the Javascript tests and examine variables?

I am currently developing a Dapp and using truffle test to verify the contract. However, I find that I am also debugging the Javascript that runs the test with a lot of console.log() statements. This ...
5
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 ...
5
votes
4answers
2k views

Can't get Metamask account in javascript

The command: web3.eth.accounts Returns an empty array despite Metamask having one account, how should I be retrieving the accounts in a way that will work with Mist and Metamask?
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 ...
5
votes
3answers
974 views

Can a smart contract record IP address of a sender?

Can a smart contract record IP address of the one's using it? I mean, is it possible to implement on Solidity?
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 ...
5
votes
2answers
648 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 ? ...
5
votes
1answer
877 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
2answers
4k views

How would you integrate Ethereum smart contracts into an existing node/react project?

I have an existing node/graphql/mongodb/react/redux project that is in beta and I would like to integrate Ethereum smart contracts to be able to save transaction information into the block chain. Is ...
5
votes
1answer
808 views

How to generate an Ethereum “brain wallet” in Javascript?

Namely, enter string -> get private key?
5
votes
2answers
334 views

How do I fix Javascript stack overflows when compiling very large file with solc?

If I compile a very large file with solc the stack overflows. This will happen most commonly in node because the default stack is only 984kbytes, which is strangely what you would expect for a 1990s ...
5
votes
1answer
108 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 ...
5
votes
1answer
291 views

Accessing custom JavaScript functions via RPC API on Geth

Geth allows me to define & load my own custom JavaScript functions with --preload flag or require() on Geth console. But is there way to access my functions via RPC interface? Like : curl -H "...
4
votes
2answers
1k views

Remove trailing zero from web3.toAscii() conversion

I have a contract that returns a bytes32 type variable and I'm currently testing it with truffle and javascript. The original data ['Roberto', 'Juan', 'Andrea'] This array is what i get as a ...
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?

1 2 3 4 5 13