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
18 views

error comparing numbers in smart contract (Big Number)

I am unable to understand when all do we need to convert numbers to bigNumbers for asserting to be equal. In some cases by mistake i missed to convert integer variables to bigNumber and they worked ...
0
votes
0answers
84 views

Web3 error: “value out of bounds” when passing in value for smart contract call

When calling a function on a smart contract that takes a tokenID, I pass in the tokenID into web3 - but web3 then parses that string into another value it seems, pads it to the left with a ton of ...
0
votes
0answers
16 views

Why does my web3 not execute this smart contract function?

Good day, I am busy with a small project trying to call a buy() function on an Ethereum Smart Contract. This Contract is found on the Ropsten Test Network here:https://ropsten.etherscan.io/address/...
0
votes
0answers
25 views

I cannot transfer the rights to use the smart contract to another wallet

I have a smart contract. I own, it belongs to my wallet. I am trying to implement a function to transfer the OWNERSHIP of this smart contract to another wallet. I have two solutions, but for some ...
0
votes
1answer
25 views

Keccak256 hash different in solidity and web3js

I am trying to sign a message in NodeJS and verify the signature with smart contract. Here is my code: async function prepareAndSignMessage(to, amount, referenceTransaction){ let contractInstance =...
0
votes
0answers
52 views

I have a problem with the transfer of ownership by a smart contract

I have a smart contract. I own, it belongs to my wallet. I am trying to implement a function to transfer the OWNERSHIP of this smart contract to another wallet. I have two solutions, but for some ...
0
votes
0answers
11 views

toNumber in test.js

I am creating a test.js for my smart contract. I forgot to use "toNumber" while testing some uint variables to be equal in some cases and it executed without any error. So in what all cases ...
0
votes
0answers
118 views

Trying to interact with ganache-cli fork through script

const {ChainId, Fetcher, WETH, Route, Trade, TokenAmount, TradeType, Percent} = require ('@uniswap/sdk'); const ethers = require('ethers'); const chainId = ChainId.MAINNET; how would I specify it to ...
0
votes
1answer
94 views

Hello. I have a problem with a smart contract transaction between users. Error: gas is missing

I have a problem with a smart contract transaction between users. Error: gas is missing. Here is my function: async function transactionContract() { let signerAddress = gettingOwnerByKey( &...
0
votes
0answers
142 views

how to send a transaction using sdk uniswap.org

i am trying to create and send a transaction to https://app.uniswap.org using SDK https://uniswap.org/docs/v2/smart-contracts/router02/ uniswap has two functions (swapExactTokensForETH and ...
-1
votes
1answer
290 views

web3.js: How to convert Wei to Ether? [closed]

Im trying to covnert wei to ether in my node.js script let myBalanceWei = web3.eth.getBalance('0xF33b5a2B692bE695d6FD6f3136eB8919f2666e3a').then(console.log) let balance = web3.utils.fromWei(...
0
votes
1answer
44 views

Hyperledger Besu: Unable to decode the hex string returned by solidity function containing multiple values

I have set up a Hyperledger Besu network for private transactions using Orion. I am using a javascript client to write to and read data from a smart contract written in Solidity. I am following the ...
0
votes
0answers
40 views

Why is my pair price value undefined?

I'm still pretty fresh to all this code life, please help me out. I am writing this price scanner to get the prices of pairs in Uniswap. Even though console.log(tradePrices) shows me an object with ...
0
votes
0answers
21 views

New to blockchain development

hope everyone's doing ok. So I am really interested in blockchain development. My programming experience so far has been C++ and a little bit of Python. I know the basics of Javascript as well. So I ...
2
votes
1answer
20 views

Accessing struct members

Can we access the struct member using a variable as we access in JavaScript? For example: struct Abc { uint256 a, uint256 b } Abc xyz; string memName = 'a'; I want to do something like ...
0
votes
1answer
245 views

Why is my for loop not fetching multiple token data?

I'm a little bit noob, so bear with me, but I love the blockchain very much and that's why I'm here, so please hear/help me out. I am building a price scanner for Uniswap, so I have this program to ...
0
votes
1answer
32 views

JS Testing: A contract calling a function in another contract which creates a contract

I want to test three contracts in total: Main.sol, Factory.sol, PCE.sol Here's the flow I want: accounts[0] calls factoryStart in Main.sol Main.sol should call a function in Factory.sol, passing the ...
1
vote
1answer
176 views

message: 'invalid argument 0: json: cannot unmarshal hex string without 0x prefix into Go struct field SendTxArgs.value of type *hexutil.Big'

I am using a JSON RPC request and source code is as follows: var options ={ url: "http://127.0.0.1:8545", method: "POST", headers: {"Content-Type":"...
0
votes
0answers
15 views

Ethereum data reading and writing time fluctuation for web3

I have created a web app for sending and receiving data in ropsten testnet. The average result of writing Data to the blockchain and reading it. The average is calculated for 5 transactions. Here data ...
1
vote
1answer
129 views

Why am I receiving invalid transaction hashes?

I am very new to this whole ethereum and web3 part. I've learned from this tutorial Link Here about how it is suposed to work and what information should my code deliver to me. But for some reason all ...
1
vote
0answers
73 views

Cannot read property 'methods' of null

My teammate has deployed ERC 20 token to rinkeby test network using the truffle openzeppelin code. Now I wanted to interact with that token by using ABI and the contract address of that token using ...
0
votes
0answers
11 views

Button to interact with a smart contract function

I have this function on a smart contract: function togglePlayerReverse(bool _isReverse) public { playerReverse[msg.sender] = _isReverse; } I want to use this button to allow the ...
1
vote
0answers
16 views

How do I do get the text from a failed `require` in Javascript?

I have a function in my smart contract that has several require clauses. I'm using etheres.js to call the it from React. When it fails, all I get in the JS Error object is the message "the ...
0
votes
1answer
22 views

Time-dependent test unexpected behavior at 1st attempt, expected behavior at 2nd attempt

I'm trying to test a contract in which functions should require certain timestamps. Parts of code are eliminated for readability: Here's the problematic part of the contract : PCE_Contract.sol pragma ...
1
vote
0answers
1k views

Calculating annual percentage yield (apy) value for Uniswap pairs

I wants to calculate annual percentage yield for a token pair listed on uniswap like this. Is there any API which I can use to retrieve the value? How can it be directly calculated?
0
votes
0answers
184 views

Uncaught (in promise) TypeError: Cannot read property 'deployed' of undefined

I am working on a truffle dapp project. Other than init(), initWeb3(), and initContract(), I have been doing fine interacting with my contracts in several JavaScript functions, until I created my 9th ...
5
votes
1answer
1k 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 ...
0
votes
1answer
3k views

ReferenceError: cannot access 'CONTRACT' before initialization

I'm trying to test a single smart contract (PCE_Contract.sol) with (PCE_Contract_test.js) using Truffle. When I run Truffle test, console output is : ReferenceError: Cannot access 'PCE_Contract' ...
0
votes
0answers
115 views

How To Resolve Uncaught (in promise) TypeError: web3.fromWei(…).toNumber is not a function

i have problem Uncaught (in promise) TypeError: web3.fromWei(...).toNumber is not a function if I delete the code .toNumber () will be like this this my code app.js App = { web3Provider: null, ...
1
vote
1answer
77 views

Infura: certificate has expired error when deploying on Rinkeby

I was trying to deploy some contracts on Rinkeby using Infura, and got the following error: Error: certificate has expired\n at TLSSocket.onConnectSecure (_tls_wrap.js:1088:34)\n at TLSSocket....
0
votes
1answer
137 views

Uncaught ReferenceError: TruffleContract is not defined 2

Firstly, I have viewed (Uncaught ReferenceError: TruffleContract is not defined) and am getting the same error for my smart contract: However, I received this error while having the contract script ...
0
votes
2answers
66 views

Getting data from array to the table

I get data from array. This is my result: 0,0,1602907512,1602907764,1602907512,1602907764,60000000,90000000 I need like that: 0,1602907512,1602907512,60000000 0,1602907764,1602907764,90000000 How ...
0
votes
1answer
412 views

Convert Hex Number from Solidity

var contract = await tronWeb.contract().at(contractAddress); var result = await contract.getPlayerDeposit("").call(); Output: I got in array: (4) [Array(1), Array(1), Array(1), Array(1)] 0: ...
1
vote
1answer
412 views

How to get privateKey from Metamask by code? [closed]

Try to create ether wallet by privateKey from Metamask account
0
votes
1answer
19 views

The network id specified in the truffle config (4447) does not match the one returned by the network (4777)

Please, the error messsage is in this imgur link, how's that even possible? They are the same network, but I still cannot test my smart contract via Truffle. https://i.stack.imgur.com/vykIa.jpg Code ...
2
votes
0answers
74 views

How to watch/wait for events in JavaScript + Truffle?

I'm learning to develop Oracles, and, like all of us, I've encountered a dated article. After fixing all the Solidity changes (version, adding emit to fire an event, changing constructor function to ...
0
votes
0answers
194 views

How to get events from transaction receipt in web3JS ( Solidity )

I have tried using events.eventname.returnValues[index] but I am not getting any response. Below is the smart contract code - pragma solidity 0.5.12; contract Dflip{ uint contractBalance; ...
0
votes
1answer
89 views

How to call contract function [closed]

I need to call function from my contract. I got: Uncaught (in promise) TypeError: contract.getBadgeOwner is not a function async function a() { let contract = await tronWeb.contract().at(".......
1
vote
1answer
133 views

Where to define the MetaMask window.ethereum.on Listener

I have tried to include the window.ethereum.on listener to detect account changes in MetaMask, in my mounted () {} method. When the listener is triggered, it itself triggers the location.reload() ...
0
votes
0answers
14 views

Transaction Callback Function Doesn't Run

I'm running the following code as part of a truffle test: electionController = ElectionController.new(districtsNo,districtFactory.address,voteTokenFactory.address); function createVoteToken(...
2
votes
0answers
675 views

Contract call: data out of bounds

I'm working on a nextjs/react project in which i want to fetch the health factor of an address on AAVE. This can be done by calling getUserAcountData(address) on the lending pool contract. I can ...
0
votes
0answers
23 views

howt to generate AST tree form (not in JSON form) from Solidity File (.sol)

I have .sol file and want to generate AST only from .sol file. My scenario is that at the command line (after installation some package), I just have to give a command like package_command --AST [from ...
1
vote
1answer
69 views

How to subscribe to transaction with a smart contract in web3js?

I am trying to write a web3js code. I have already written it using web3j (java) and now i want to do exactly same thing but using web3js. I have seen documentation and stuff, but i am not able to ...
4
votes
1answer
5k 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 ...
0
votes
0answers
297 views

TypeError: Cannot read property '0' of undefined AND TypeError: eventAdded.watch is not a function

I'm currently trying to test run source code from GitHub based on a 2018 tutorial where solidity was using version 0.5.16. I'm currently using truffle v4.1.14. Appreciate any help. Thanks! In the ...
1
vote
1answer
110 views

ComponentDidMount doesn' detect Metamask change account

I'm quite new to Web3 and Metamask and would like to ask how should I change the basic componenDidMount of the React truffle box so that it can detect and change accounts when I'm switching an account ...
1
vote
2answers
224 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?
0
votes
1answer
206 views

Linux: node-gyp installation woes in scrypt package

This has happened to me enough times that I figured it would be a public good to make a question out of it. There is a npm package called scrypt which is used in a number of Ethereum related npm ...
2
votes
1answer
2k 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
91 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: [...

1
2
3 4 5
15