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
0
votes
1answer
15 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 ...
0
votes
0answers
32 views

Solidity OpenZeppelin Documentation: Import other Contract not working

I just completed the whole documentation for OpenZeppelin and everything was working fine except the import command. I created a folder in the folder Contracts and placed Auth.sol in there. Paths: [...
0
votes
0answers
29 views

Ethers contract call reverted while passing on etherscan interface

I'm trying to implement 1inch exchange's getExpectedReturnWithGasMulti method in ethers.js. The contract is deployed at: https://etherscan.io/address/0x6e858ea1015e1c8da176f057d74dae0f35675aeb When I ...
0
votes
1answer
36 views

How to set values for Solidity contract state variables from JavaScript front-end?

I am trying to set values to the following contract public state variables from a frontend javascript code. But it seems not working. Contract public state variables: // Current state of the auction. ...
0
votes
0answers
10 views

require() statement to use for including Ganache GUI in the Dapp not Canache-cli

When using ganache-cli, we assign it using the require() statement. How do we do the same for ganache GUI? I don't want to use the ganache-cli for my app execution. Also how do I assign the provider ...
0
votes
1answer
27 views

Get current metamask account method not working anymore

I was using the following method to access the selected account on metamask through web3 v1: //metamask method that refresh the active account in the web this.web3.currentProvider....
0
votes
0answers
22 views

Web3- Sending data to Ganache and then loading a new page to retrieve the same data back

JAVASCRIPT const address = '0x2537155193458a51c99d840e3dBc1f60E004aA85'; var contract = new web3.eth.Contract(abi,address); console.log(contract); $('#invoice-btn').click(function(){ contract.methods....
0
votes
1answer
21 views

String To bytes Error

I am trying to take user input strings and convert them to bytes32 and bytes5 for a contract built in Solidity 5.11, I tried 32 and 5 character long random strings respectively however they are not ...
0
votes
0answers
16 views

Is there a way to get revert message by my client?

I have a smart contract with this simple function: function addUser( string memory _username, string memory _nome, string memory _cognome, string memory _email) public isOwner() { require(bytes(...
0
votes
1answer
28 views

web3 eth return returns a nonexistent transaction hash

I'm trying to create transactions something like this: var sender = meth.eth.accounts.privateKeyToAccount(data.fromPrivate) meth.sendTransaction({ sender, to: data.to, amount: data.value, }, cb) ...
0
votes
1answer
66 views

Uniswap V2 smart contract keeps getting reverted in JS

I'm trying to swap tokens using Uniswap v2 interface. The code of the contract is here. I'm able to deposit Eth to the contract and but I'm not able to invoke the swapEthForTokenWithUniswap() ...
0
votes
1answer
26 views

Array lenght and data miss match while storing data of events

Can someone help me in finding what is wrong here a why the length of task info is 0 even the taskInfo has some data. I'm using events to fill the taskinfo array. I'm stuck at this place for almost 2 ...
1
vote
0answers
64 views

Solidity function calls from javascript work locally but fail on ropsten,kovan etc with Error: Returned values aren't valid, did it run Out of Gas?

I have a smart contract whose function calls works fine when called locally using javascript and ganache. But when I deploy to ropsten and others, the calls to its functions fail with Error: Returned ...
0
votes
1answer
31 views

How can you make HTML Text Box print the value of console.log?

How can I enter input data value in HTML Text Box? The output is good in console.log, but the HTML Text Box displays the error Object Promise. I want to know how to print the value of web3.eth....
0
votes
0answers
19 views

Ether transaction does not reflect in ganache

Hi am developing a etherium DAPP. In that for every user registration some ether will get transfer from user to contract... Everything work perfect but the transacted ether is not reflecting in ...
0
votes
1answer
34 views

address(this) in solidity is returning wrong contract address

This is my cantract code which I was using in truffle pragma solidity 0.5.16; contract Test { function getAdd() public view returns(address){ address add = address(this); return ...
0
votes
2answers
29 views

Are events collected in Web3js asynchronously?

I am collecting a set of previously generated events, based on certain filters/test, and trying to display them on my HTML page. The code I am using to fetch the events is as follows: var eventList = ...
0
votes
1answer
59 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 = ...
1
vote
1answer
65 views

DApp examples containing complete source code

can someone provide me some high quality ethereum dapp codebase examples? This should comprise of not only the smart contract codebase but also the app codebase , complete with the front end UI (...
0
votes
0answers
12 views

migrate error from new buffer(process.env)

I follow the book Ethereum from Gavin Wood and when i use truffle migrate --network ganache it gives me following error; TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type ...
1
vote
0answers
33 views

Contract not returning error to React Interface

I have a contract which I've tested with Mocha and Remix and is working just fine. The problem is when I'm running it with my React Interface. When I call a function in my solidity contract that ...
0
votes
0answers
30 views

Kovan transaction never being mined

I have setup an Infura account to send transactions on the kovan network. This is the code I want to use to send ether to another account (current one has 1 ether from a faucet): var Web3 = require('...
1
vote
1answer
90 views

Drizzle cacheSend outputs “cacheSend is not a function” error, but the tx works when using send

I'm using Drizzle and react-hooks in my new open source project, but cacheSend outputs always "cacheSend is not a function" This line of code with send works as expected const stackId = contract....
0
votes
1answer
19 views

Smart contract function not returning expected output

I'm quite new at this and I'm learning both Solidity, Javascript and React to play around with smart contracts. My contract ran well in Remix and in a local test net. I ran a bunch of tests using ...
1
vote
1answer
42 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://...
0
votes
1answer
17 views

input from second form won't display [closed]

The project is to change someone's name, and I have two forms for two names. When I run the code in solidity, I can change the names, no problem. When I run it with ganache, the name change in the ...
0
votes
1answer
20 views

ERC20 Transaction failing due to invalid nonce value

I am trying to send an erc20 transaction but I keep getting an error telling me that the account I'm sending the transaction from has a nonce value of 1 while the tx has a nonce value of 31613. I am ...
0
votes
0answers
33 views

Web3.js Batch Request Limit?

I'm trying out Batch Request provided by web3.js. In the example below I want to test making 300 transactions but i get the error log displayed below. I'm trying to figure out the error log but it ...
0
votes
1answer
17 views

What does instance refer to in solidity/JavaScript

DToken.deployed().then(function(instance){ token = instance; }) This code I saw in truffle test. Can someone please tell what does this "instance" parameter refer to?
0
votes
1answer
23 views

web3.eth.defaultChain returns undefined

Hi I am trying to make a call to the Dai contract in the Kovan testnet using web3.js and have to set the value of web3.eth.defaultChain to 'kovan'. The docs state that the default value for web3.eth....
0
votes
1answer
20 views

How to send the RFID card no read using Raspberry Pi to smart contract so the details can be stored on Ethereum blockchain? [closed]

Raspberry Pi reads an RFID card and has to send the RFID number to the smart contract to check further details related to the RFID number. Based on the details the payment is done and stored on the ...
0
votes
2answers
47 views

Error sending transaction to smart contract [closed]

I have problem with this, I'm doing a tutorial about how to interact with blockchain through web3, I get some response from blockchain, but the problem is when I try to send transaction or try to ...
0
votes
0answers
20 views

web3 getTransactionReceipt instant response

How come the second time i call getTransactionReceipt with the same transactionhash i get an instant response? code: async function test() { prmoise1 = web3.eth.getTransactionReceipt( '...
0
votes
1answer
31 views

Unhandled promise rejection

The code below gives me the exceeds allowance or always failing transaction error but when i check my contract on remix i can see that the transaction goes through, makes the correct state changes ...
0
votes
0answers
23 views

Just not able to install Web3 through powershell

After reading a lot of articles about how to install Web3j in windows. I also tried following this article : https://kauri.io/generate-a-java-wrapper-from-your-smart-contract/...
0
votes
2answers
58 views

gas exceeds allowance

I'm testing my smart contract on ropsten and I have written an async function that lets me send TRANSACTION transactions from TRANSACTION different accounts. For some reason when TRANSACTION > 20 i ...
0
votes
1answer
61 views

How to import web3 utils in front end Javascript

I need to use a web3.utils.soliditySha3 function in my javascript but web3.utils gives: Cannot read property 'soliditySha3' of undefined My script can't use .require as well. I tried: <script ...
0
votes
1answer
29 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: ...
0
votes
1answer
15 views

How to large amounts of old block

I have to scan a large amounts of old block. I using subcribe newBlockHeaders so I have new_block.number (2s/block). Then I find in db the latest block number (db_block.number). I use for(i=db_block....
1
vote
1answer
22 views

Exit process after sending multiple tx asynchronously

I have written a function that allows me to send an arbitrary amount of transactions, asynchronously, to my smart contract. However the process stays open even after the last transaction has finished. ...
2
votes
2answers
151 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 ...
1
vote
1answer
27 views

How to fix Data location must be “memory” for return parameter in function, but none was given.?

pragma solidity >= 0.5.0 < 0.7.0; contract Adoption { address[16] public adopters; function getAdopters() public view returns(address[16]) { return adopters; } function adopt(uint ...
0
votes
0answers
14 views

Proper way to fire smart contract function passing an array with web3js

I'm using web3js version 0.20.7 The smart contract originally had a function (called whiteListAddress(address _address, bool value) ) that took an address and a boolean value, which was called like ...
0
votes
1answer
24 views

Get contract's balance in js test

When getting contract's balance on Remix, it returns the correct answer. But when the same function is called with JS Test, it returns a lot of junk. I referred to How to get a contract's balance ...
0
votes
1answer
45 views

Web3 js proper way to call a Reading contract function

So i recently took over a project that had been abandoned for a while, which involves an ECR20 smart contract and the use of the web3 library to communicate with the smart contract. I've been trying ...
1
vote
1answer
36 views

keccak256 output is different on ruby vs javascript…?

Ruby ethereum libraries use: https://github.com/phusion/digest-sha3-ruby require 'digest/sha3' '0x' + Digest::SHA3.new(256).hexdigest('0x0') => "...
0
votes
1answer
75 views

How can I get the ABI from solc.compile? (^0.6.4)

In pragma solidity ^0.6.4; I wrote a contract and can get the byte code as follow: const solc = require("solc"); const path = require("path"); const fs = require("fs"); const inboxPath = path....
0
votes
1answer
37 views

How to listen to Metamask Ethereum events

I am trying to listen to the 'chainChanged' event for Metamask, but the event never fires. When running the following snippet, the I get a console.log of the chainId once, but the chainChanged event ...
0
votes
2answers
21 views

Transaction won't be mined / Failed signing of transaction

I'm trying to send a transaction that writes somesthing on ethereum(kovan) but it seems my transaction is not mined and probably not even send to the network? All my view requests to ethereum work, so ...
1
vote
0answers
27 views

Why ethers.js sign function not working?

I am using the ethers.js library, and am trying to code a transaction. Here is a snippet where I connect a wallet to a provider, connect to a contract I want to call a function in, and try to call the ...

1
2 3 4 5
14