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
96 votes
12 answers
50k views

Common useful JavaScript snippets for geth

In Geth you can loadscript any javascript 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(&...
47 votes
6 answers
43k 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 ...
Paul S's user avatar
  • 4,271
57 votes
6 answers
114k 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 ...
Ernane Luis's 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 ...
yanik's user avatar
  • 463
29 votes
3 answers
13k 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 ...
Jehan's user avatar
  • 783
5 votes
2 answers
4k 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?
BokkyPooBah's user avatar
  • 40.3k
10 votes
1 answer
11k 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) => { // ...
Sowmay Jain's user avatar
17 votes
3 answers
15k 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....
PragMan's user avatar
  • 173
16 votes
6 answers
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?
Diego Cerdan Puyol's user avatar
16 votes
6 answers
26k 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 ...
Jorge Alvarado's user avatar
5 votes
1 answer
3k 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 ...
galahad's user avatar
  • 3,920
3 votes
3 answers
17k 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 ...
Kravitz's user avatar
  • 447
0 votes
0 answers
471 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"], ...
Questioner's user avatar
  • 2,670
27 votes
5 answers
22k 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 ...
Mindful's user avatar
  • 393
7 votes
2 answers
5k 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 ...
Jesbus's user avatar
  • 10.4k
7 votes
1 answer
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,...
Aditi's user avatar
  • 327
3 votes
2 answers
2k views

Ethers js deploy contract with balance, payable constructor

I have a smart contract with a payable constructor. I'm trying to figure out the syntax with ethers js how I can deploy the smart contract and send an initial balance with the deployment. const ...
Brandon's user avatar
  • 31
3 votes
3 answers
3k views

Hardhat deploy TypeError: ethers.getContract is not a function

I'd look for an alternative but not being able to use the ethers module is going to drive me nuts down the road. The code was copied from Patrick's Solidity Javascript course, the NFT section, Lesson ...
Domini's user avatar
  • 171
1 vote
1 answer
821 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){ ...
Alireza's user avatar
  • 533
35 votes
7 answers
50k 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'); ...
ErwanLent's user avatar
  • 541
17 votes
5 answers
14k 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 ...
Mikko Ohtamaa's user avatar
17 votes
4 answers
7k views

How to open the JavaScript console on Parity?

There is nothing like parity console. How to open the JavaScript console on Parity?
q9f's user avatar
  • 32.9k
14 votes
2 answers
21k 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 ...
Wapiti's user avatar
  • 419
12 votes
2 answers
20k 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 ...
Zach's user avatar
  • 571
9 votes
5 answers
31k views

insufficient funds for intrinsic transaction cost

i've codded a script using js to trigger a buy on uniswap. the way i achieved this is through importing uniswaps smart contracts using this line of code: const router = new ethers.Contract(addresses....
Aaron Klich's user avatar
9 votes
1 answer
19k views

How to make transactions using private key in web3?

I have account private key, contract address and abi and I need to call contract function with this account. Is it possible?
Agniezhk's user avatar
  • 321
8 votes
4 answers
14k 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 ...
pmcoelho's user avatar
7 votes
1 answer
12k 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 ...
Hokkyokusei's user avatar
7 votes
2 answers
6k 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, '...
Teleporting Goat's user avatar
7 votes
1 answer
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.
HodlDwon's user avatar
  • 927
6 votes
2 answers
1k 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 ? ...
jayD's user avatar
  • 2,462
6 votes
3 answers
4k 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:...
pd176's user avatar
  • 439
6 votes
1 answer
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?
MaiaVictor's user avatar
  • 3,177
5 votes
1 answer
126 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 ...
Matthew Patience's user avatar
5 votes
2 answers
7k 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/...
Vivek Sadh's user avatar
5 votes
1 answer
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 ...
pd176's user avatar
  • 439
4 votes
1 answer
845 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?
Paul's user avatar
  • 43
4 votes
1 answer
3k views

Recover JavaScript Signed Message in Python Web3

Running into problems taking a signed message from Web3.js, and recovering the signing address in Web3.py. Here is my code in JavaScript to create a signed message: async function sign_message() { ...
Shawn Tabrizi's user avatar
3 votes
1 answer
9k views

Window.ethereum undefined on tab with local webpage

I have the metamask extension. When I do typeof(window.ethereum) in the console for a chrome tab, I get the type as object. However if I open mywebpage.html in a tab, which is just a heading around: &...
pongoS's user avatar
  • 143
3 votes
1 answer
476 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 ...
Lee's user avatar
  • 8,488
3 votes
2 answers
680 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 ...
Consy's user avatar
  • 592
2 votes
1 answer
2k views

Could not find a declaration file for module 'solc''

I have installed solc without any errors or warning, but when i am trying to run node compile.js command in cmd then i am getting following error On checking the code, i found that "const solc = ...
Vijender Singh's user avatar
1 vote
2 answers
1k 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 ...
jiebang's user avatar
  • 993
1 vote
1 answer
2k 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 ...
Questioner's user avatar
  • 2,670
1 vote
1 answer
580 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). ...
Ytsen de Boer's user avatar
0 votes
1 answer
120 views

Solidity function successful from Truffle Develop but fails from javascript

I have following Solidity Contract function, it returns values when called from truffle develop, but return empty object when called from javascript. Below is Solidity function function ...
Zeeshan Zia's user avatar
24 votes
3 answers
22k 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 ...
Sebastian Dine's user avatar
16 votes
4 answers
16k 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 ...
Zach's user avatar
  • 571
14 votes
3 answers
26k 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 ...
Louis's user avatar
  • 1,155
12 votes
3 answers
21k 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; ...
AVorobev's user avatar
  • 123