As of May 31, 2023, we have updated our Code of Conduct.

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
10 votes
2 answers
2k 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 ...
NYCeyes's user avatar
  • 235
9 votes
2 answers
9k 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)?
Raine Revere's user avatar
  • 3,500
8 votes
1 answer
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 ...
manidos's user avatar
  • 4,258
8 votes
2 answers
7k 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. ...
Jimson James's user avatar
7 votes
11 answers
9k views

TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider')

const ethers = require("ethers"); const provider = new ethers.providers.JsonRpcProvider('https://mainnet.infura.io/v3/MYKEYISHERE') web3.eth.getBlockNumber().then(console.log) Error: ...
dertobiaszwei's user avatar
7 votes
1 answer
5k 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 &...
galahad's user avatar
  • 3,900
7 votes
2 answers
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 ...
Satyam Agrawal's user avatar
7 votes
1 answer
6k 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 ...
RFV's user avatar
  • 633
7 votes
0 answers
981 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 = ..., ...
Nyxynyx's user avatar
  • 1,147
7 votes
1 answer
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?
eth's user avatar
  • 83.3k
6 votes
2 answers
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. ...
Teleporting Goat's user avatar
6 votes
2 answers
8k views

How to set msg.value in function call using ethers.js?

I've got a function in my smart contract and i want it to take an argument that sets the msg.value and then pays it into the contract: function deposit(uint256 amount) public payable { msg.value = ...
PopFendi's user avatar
5 votes
1 answer
1k 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 ...
Viktor's user avatar
  • 540
5 votes
2 answers
9k views

tx fee (2.11 ether) exceeds the configured cap (1.00 ether), how to bypass default cap?

I'm getting this error when trying to make a simple ETH(BNB) transaction with very high gas, I've tried using different scripts with both web3 and ethers.js and both throw the same error on the BSC ...
Charlie's user avatar
  • 51
5 votes
1 answer
2k views

How can access to a external file using loadScript?

I'm using loadScript in ethereum console to load a external js file: loadScript('teste.js'); // teste.js function fx() { return 12; } However when I run it in ethereum console it always returns ...
JC_92's user avatar
  • 193
5 votes
3 answers
8k views

How to generate multiple eth-addresses from one private key? [duplicate]

Is it possible to generate different multiple eth-addresses from one private key? The goal is to implement a JavaScript service that will allow a user to buy a subscription using cryptocurrency. ...
Taras's user avatar
  • 98
4 votes
1 answer
6k views

How to Keccak 256 hash in front end JavaScript before passing it to my smart contract

I would like to build a simple JavaScript (JS) front end that checks if a field submitted is the pre-image of a keccak256 hash I already know in my smart contract. I currently use the following: ...
contute's user avatar
  • 41
4 votes
1 answer
8k views

How to use infura API with web3 js? [duplicate]

How to use infura API with web3 js? Where should I put secret key?
gkucmierz's user avatar
  • 773
4 votes
2 answers
11k views

Using Web3 to pull block #, hash, and timestamp

Can anyone give me advice on using web3 to pull the latest block number, hash and timestamp using Web3? I can't get this to work, and the documentation is fairly weak from what I've seen. Once I pull ...
Forrest's user avatar
  • 65
4 votes
1 answer
6k 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 ...
Sushant's user avatar
  • 41
4 votes
2 answers
522 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 ...
mgalka's user avatar
  • 243
3 votes
2 answers
2k views

Whats exactly Ether unit return web3.eth.estimateGas, wei, gwei ...?

I am testing with function web3.eth.estimateGas and is not clear what Ether unit is returning. Looks like it's gwei, but my final calculations don't match. In my code, the EGAS returned is 84753. I ...
JTCon's user avatar
  • 673
3 votes
2 answers
308 views

Where to find the private key for my contract in blockapps?

I am trying to use blockapps-js to invoke functions on my smart contract deployed in blockapps. Since I need the private key for it, I am looking at the app/users/admin/.json file. Problem is I cannot ...
Clovis's user avatar
  • 871
3 votes
3 answers
7k views

Convert Ether to Wei without web3

I don't want to load the web3 library, I do however want to convert Either to Wei, does anyone have a JavaScript function to share. I don't mind loading a smaller library
Bill's user avatar
  • 429
3 votes
2 answers
3k views

Generating an Ethereum wallet with an existing private key

I want to understand how Ethereum works and i want to calculate the public key and wallet address from private key. I have read this tutorial: https://piyopiyo.medium.com/generating-an-ethereum-wallet-...
Bob5421's user avatar
  • 1,363
3 votes
2 answers
983 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
3 votes
2 answers
1k views

MetaMask API - How to detect if token already registered?

I'd like to prevent a user from entering my dapp until they have registered my token with MetaMask. I accomplish this using the code below, which is executed the moment the user is about to enter the ...
David Callanan's user avatar
3 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
2 answers
4k views

Ethers js estimateGas() without needing ETH in account

I am trying to estimate the gas used for a uniswap transaction. I am able to perform this on the Kovan testnet however when I try and run the same script on the mainnet it raises an error, "Error:...
Mvteyv's user avatar
  • 55
2 votes
2 answers
5k 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 ...
Ernane Luis's user avatar
2 votes
1 answer
593 views

Signing a raw transaction, wrong R and S values

I am trying to sign a raw transaction in javascript without relying on dependencies like web3, ethereumjs, etc. I am following the python tutorial found here, and porting to JS as I go: https://...
Albert Renshaw's user avatar
2 votes
2 answers
2k views

Generating random uint256 numbers in JS

I need to generate a uint256 random number offchain (in a Node.js client). Since BN doesn't have a random() function, what's the best way to do so?
Vitor Py's user avatar
  • 143
2 votes
1 answer
2k views

web3.js error: Cannot read property 'providers' of undefined

What is problem of this simple html / JavaScript / ethreumjs / web3.js code? <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title&...
Questioner's user avatar
  • 2,638
2 votes
2 answers
3k views

Error: could not detect network

I am currently trying to deploy my DApp 'nftmarketplace' to the net using Vercel on the Goerli test network. However the app is failing to connect to the blockchain and I am getting the following ...
Beau Chaseling's user avatar
2 votes
1 answer
1k views

Uniswap Universal Router - Decoding the Execute function parameters

I used the method described in this thread (Decode Uniswap Universal Router transaction in ethers.js) and decoded most of the data of a transaction at this link: https://arbiscan.io/tx/...
python_rok's user avatar
2 votes
1 answer
10k views

Ethers.js transfer event filters

In my dapp I'm building I want to update the contracts' balance of an ERC20 token automatically using the transfer event from the token contract. I have created the contract object using: const ...
Nolan Jannotta's user avatar
2 votes
3 answers
3k views

Truffle test error: Cannot create instance of Vault; no code at address

I'm trying to make a simple test in Truffle using Ganache where I call a function from a smart contract instance. This component will create a Vault and return me its address. My truffle test does ...
Antoine Delia's user avatar
2 votes
2 answers
5k views

Authenticating a user via MetaMask (like Cryptokitties)? [duplicate]

I'm trying to understand how a user could be authenticated (like a sign in) using MetaMask, similar to how Cryptokitties makes you sign up/login? From what I understand, we need to have the user sign ...
Surz's user avatar
  • 121
2 votes
2 answers
4k views

Returned error: Sender doesn't have enough funds to send tx when running offline transaction with web3

I'm trying to run the javascript following code to make a transaction to a contract function offline against a Ganache blockchain but I get the following error: "Error: Returned error: sender doesn't ...
RaphArbuz's user avatar
  • 121
1 vote
0 answers
260 views

Multithreading in web3.js [duplicate]

Is it possible to run concurrent tasks using web3.js and an Ethereum client? For example, say we have the following code to iterate through a number of blocks: var startBlockNumber = 0; var ...
Sebi's user avatar
  • 5,274
1 vote
1 answer
2k views

Synchronous requests are not supported by the IPC provider

I was trying to connect to my node via IPC using web3_ipc. But i got hit by: You tried to send "eth_getBalance" synchronously. Synchronous requests are not supported by the IPC provider. My code is ...
Prashant Prabhakar Singh's user avatar
1 vote
1 answer
932 views

{ code: -32000, message: 'insufficient funds for gas * price + value' }

I'm a beginner in blockchain and facing a huge problem while deploying my smart contract with Truffle. first my simple contract... pragma solidity ^0.8.10; contract Inbox{ string public message; ...
Adil Nehal's user avatar
1 vote
2 answers
2k views

Should an API call be in the Solidity backend or the Javascript frontend?

I am fairly new to blockchain development. I want to call a function in my contract when a condition in the API is true. Should I make this API call in my contract, or in my frontend?
ACluelessProgramer's user avatar
1 vote
2 answers
6k views

Uncaught ReferenceError: TruffleContract is not defined

I am working on a smart contract. When I try to serve my smart contract via lite-server I see following error in the browser console Here my app.js source code: https://pastebin.com/UjFuYCyQ I have ...
Faisal Memon's user avatar
1 vote
3 answers
2k views

How to dynamically load contracts data with their ABI from etherscan API?

Im wanting to pull data from a smart contract I've loaded via user address and etherscan API for the ABI. But how would I go about programmatically adding all the functions from the ABI into my ...
Zach's user avatar
  • 561
1 vote
3 answers
5k views

How to call solidity function which has array of address as an argument using web3

Say i have a contract as follows: contract A { function passAddress(address[] _addr) { // do something } } How do i call this function in my frontend application using web3. I tried using ...
Jagjot Singh's user avatar
1 vote
2 answers
1k views

Get Token Balance without using nodejs

I am trying to get Token Balance using plain javascript, no nodejs or web3. With web3 and nodejs I can do: exports.getTokenConfirmedBalance = function(node, query, abi) { return new Promise((...
Eduardo's user avatar
  • 241
1 vote
1 answer
181 views

Bundling web3js does not seem to work (Metamask app)

(This is a follow-up question from here.) From the Metamask developers faq it is stated to "bundle the version of web3 that is used during development". So I downloaded a web3.min.js version 0.20.6 ...
Ytsen de Boer's user avatar
1 vote
1 answer
2k views

Type struct storage ref[] ref is not implicitly convertible to expected type struct memory

In my function, while using my mapping to reference to an array, I keep getting the error message below: TypeError: Type struct etherGifter.CryptoGift storage ref[] storage ref is not implicitly ...
SirBT's user avatar
  • 147
1 vote
0 answers
803 views

Error: Cross origin null forbidden : ---Problem in downloading Open source contracts from Etherscan.io

UPDATED: I am trying to download source code of open source verified contract from Etherscan.io. Here is my procedure as directed by Ann. 1. Download CSV file of captioned contracts. 2. Write ...
Amir Ali's user avatar
  • 447