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
89
votes
12answers
43k 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....
45
votes
6answers
30k 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 ...
37
votes
4answers
69k 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 ...
35
votes
2answers
20k 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 ...
33
votes
7answers
42k 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'); ...
25
votes
3answers
11k 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 ...
25
votes
4answers
26k 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 ...
24
votes
5answers
21k 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 ...
17
votes
5answers
13k 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 ...
16
votes
6answers
24k 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 ...
16
votes
4answers
7k views

How to open the JavaScript console on Parity?

There is nothing like parity console. How to open the JavaScript console on Parity?
16
votes
6answers
16k 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?
15
votes
2answers
7k views

Listening to events using ethers.js on a hardhat test network

I am currently migrating a truffle project to hardhat. I am facing a problem with listening to events. I have a simple ERC20 token and want to listen to the Transfer event. I am running the contract ...
14
votes
9answers
15k views

Hardhat - How to interact with a deployed contract?

I can deploy a contract using ethers and Hardhat with the following: const myContract = await hre.ethers.getContractFactory("SomeContract"); const deployedContract = await myContract.deploy()...
14
votes
2answers
18k 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
3answers
10k 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....
11
votes
3answers
14k views

Is it possible to send transaction in Binance Smart Chain using web3 and ethereumjs-tx?

I want to send transaction in Binance Smart Chain and I got an error: new Error("Chain with name " + chain + " not supported"); const Tx = require('ethereumjs-tx').Transaction; ...
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
1answer
4k views

Getting Tx is not a constructor when executing this program

Here is my code. I am trying to send ether from one account to another. var Tx = require('ethereumjs-tx') const Web3 = require('web3') const web3 = new Web3('https://ropsten.infura.io/v3/...
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
3answers
8k views

How to check whether MetaMask is installed?

How to check from client-side JavaScript whether MetaMask is installed?
9
votes
5answers
22k 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": ...
9
votes
2answers
8k 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)?
9
votes
2answers
1k views

Run a single hardhat test

I have a test file in hardhat like so: const { expect } = require("chai"); describe("contract tests", function () { it("does function one", async function () { ...
9
votes
1answer
7k views

How to programatically change the current network with MetaMask

I would like to have a button that switches between main net and ropsten on my app, in order to do so I need to programatically change the current network with MetaMask. But I cannot find aby ...
9
votes
3answers
7k views

How to automatically get user's wallet info if they are connected but NOT show the metamask pop up if they are not?

I don't want metamask to pop up on page load forcing a user to connect, so we only connect via a button - but after a user is connected if they refresh the page - they need to press the button again ...
9
votes
1answer
361 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
14k 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 ...
8
votes
1answer
7k views

How to convert BN result into readable string or number in ethjs?

I'm receiving the result in BN format. How can I convert it into actual string or number? I'm using ethjs library to interact with Smart Contract. token.totalSupply().then((totalSupply) => { // ...
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 ...
8
votes
3answers
5k views

Sending multiple transactions in the same block with incremented nonces

I need to send 0.1 ETH to 10 unique addresses from the same address at the same time. I am manually incrementing each transaction's nonce, and the transactions are sent successfully. However, each ...
7
votes
2answers
3k 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 ...
7
votes
2answers
4k 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 ...
7
votes
1answer
4k 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
4answers
6k views

How to get events emitted by a transaction with web3.js

I'm writing a user interface in Javascript and I'm using the web3.js library. I have the transaction hash of a confirmed transaction. I would like to get an array of all events emitted by that ...
7
votes
2answers
5k 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
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?
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
2answers
4k 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 ...
7
votes
2answers
7k views

In ethers.js how to deal wait()?

In ethers.js, provider.sendTransaction(rawTransaction).then((transaction) => { // A full Transaction Response is returned // - from // - to // - gasLimit, gasPrice // - nonce ...
7
votes
1answer
159 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
2k 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
1answer
9k views

How to get a token pair's uniswap trade history?

What I am trying to do is this :- Given an pair (say DAI/ETH pair), i want to display the latest 10-15 trades (buy, sell, add to pool and remove from pool) and also display a graph of price for that ...
6
votes
2answers
5k views

Truffle test, logs do not include an emitted event

I am calling a contract function which emits an event in a transaction. This transaction should include the event and is typically visible via: const receipt = await contractInstance.someFunction() ...
6
votes
2answers
5k 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. ...
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
3answers
7k views

Web3 create account from mnemonic + passphrase

I'm trying to create an ethereum account using web3-js by providing a mnemonic + passphrase (created with BIP39-js) but can't seem to find an implementation of web3.eth.accounts.create() that accepts ...
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
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. ...

1
2 3 4 5
20