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

I am getting the following error : RPC Error: Invalid parameters: must provide an Ethereum address

I am getting the following error: RPC Error: Invalid parameters: must provide an Ethereum address. It is a simple code to send transactions using a metamask chrome extension. <script> let ...
1
vote
1answer
12 views

Encryption using public key from eth_getEncryptionPublicKey metamask function

I'm trying to encrypt data/files before uploading them to IPFS and I want to do this using metamask provided public and private keys. For this, I have tried using eth_getEncryptionPublicKey but this ...
0
votes
1answer
14 views

Calling a solidity function without a wallet using ethers.getDefaultProvider

I am trying to call a function from my solidity contract which shows how many nfts have been minted so far, I want the front end user to be able to see the number even if they don't have a wallet in ...
0
votes
1answer
16 views

How to verify allowed addresses using a Merkle Tree in Node.js [closed]

I have set up a server using Node.js and Express. I am unsure if I need a database but I do have MongoDB available if needed. The method I'm trying to do is to capture the wallet address from the ...
0
votes
0answers
74 views

disconnect wallet from metamask using ethers js

I've created a website on WIX (a web editor) and thought that I could add my code to engage with metamask and the smart contract that I've created, turnes out that wix doesn't support web3 so I ...
0
votes
0answers
9 views

Deploying smart contract using vanilla JS with existing bytecode

I'm not sure if it's possible to deploy a new smart contract using plain Javascript if I include the bytecode and ABI. I copied and paste my ABI and bytecode below at MEW and I could deploy them. But ...
0
votes
0answers
11 views

Web3js Deploy contract is asking two transaction confirmation on metamask

I am new to web3js and trying to deploy smart contract using metamask. During the deployment, I am receiving two times the transaction confirmations from metamask. Could someone please help me. import ...
0
votes
1answer
40 views

[SOLVED]: CANNOT find my pending transactions using: ether.js & [provider.on("pending") and provider.getTransaction(tx)]

I am using Quicknode and ether.js to monitor pending transactions using the following code: provider.on("pending", async (tx) => { provider.getTransaction(tx).then(function (transaction)...
0
votes
0answers
29 views

Retrieve wallet address after connecting Metamask with Web3.js

I got this code off github which allows you to connect to MetaMask using web3.js and also to make payment. I then modified it to Display a Connect Button when user is not logged in by checking if the ...
1
vote
1answer
104 views

If a function returns two or more values and I wish to use one of the two in another function, how do I do that?

I have a function xyz : uint256 a; uint256 b; function xyz() internal view return(uint256,uint256){ return (a,b); } Now, I wish to use the first return value in another function (for eg): uint256 c; ...
0
votes
1answer
17 views

EthersJS JSON to sha256: Error string too long

what I'm trying to accomplish is creating a hash of a JSON object. This will then be used as a bytes32 parameter when minting a token. I thought the best way to go about this is to first stringify a ...
0
votes
1answer
29 views

How to handle MetaMask disconnecting from dapp?

How do you detect when a MetaMask user disconnects their wallet from your dapp? I see there is a disconnect event, but this is a for disconnecting from RPC - I want to know when the user has ...
0
votes
1answer
23 views

swapExactTokensForTokens not working!

We are trying to "swapExactTokensforTokens" for swapping any token, and it runs well, but we get this error at the blockchain: TRANSFER_FROM_FAILED https://polygonscan.com/tx/...
0
votes
1answer
21 views

Store PrivateKey in webapp to send in transaction

I have a big question regarding the security of my system. Well, what happens.. I developed my contract using ECDSA, that is, it is only possible to do actions in my contract if the transaction is ...
0
votes
0answers
21 views

Trying to use an Alchemy Websockets address to subscribe to an event but it errors out when it tries to update

Here is the script: const Big = require('big.js'); const blk = require('./blockchain'); const UniswapV2Pair = require('./abi/IUniswapV2Pair.json'); const cc = require('./common_code'); const ...
0
votes
0answers
14 views

Why ISN'T my GUI interacting with my smart contract?

I successfully deployed an Ethereum smart contract within the Web3 Provider environment, and I am able to successfully interact with the various functions only via the Remix IDE. Find below my ...
0
votes
0answers
6 views

Ethereum app looking at wrong Address from Migrations.json

I developed a webapp for ICO's (KOVAN TESTNET). It works just fine locally but when I push the files to my live site, it uses a different address for my sales contract. it is fine for my token ...
0
votes
1answer
30 views

Check if NFT tokenURI is an image or a video

Is there a way to check if the file I'm loading as a URI is an image or a video. so that I can use 'img' tag for the images and 'video' tag for the videos.
1
vote
1answer
12 views

Transaction not created by ethers.js

I have written the following code to try to mint an NFT based on some git repos I saw. The code runs successfully and outputs a transaction hash, but the hash never resolves to anything on Rinkeby ...
1
vote
0answers
26 views

Cannot run default JS script from within Remix?

just getting started with Remix. I want to run the default deploy_ethers.js script and see there are two ways to do it: Right-click on the script and hit "Run". Open the file and run remix....
1
vote
1answer
20 views

Why doesn't Truffle's testing framework automatically retrieve fresh values of public state variables after every interaction with the contract?

I have the following simple smart contract defined: contract LoanApplication { struct Applicant { bytes32 ssn; bool hasApplied; } struct Loan { string loanID; uint ...
0
votes
1answer
56 views

encode_abi encode function call

I am trying to convert Javascript code to Python and believe the equivalent "web3.eth.abi.encodeFunctionSignature" function in JS to encode ABI in Python is with the "encode_abi" ...
0
votes
1answer
15 views

smart contract function not returning correct results when invoking from javascript

// SPDX-License-Identifier: MIT // solium-disable linebreak-style pragma solidity >= 0.4.22 < 0.9.0; import "./Ideator.sol"; import "./Investor.sol"; contract ContractOwner { ...
0
votes
1answer
17 views

Is it necessary to convert a file into a "Buffer or Readable stream" before adding it to IPFS?

I've uploaded some files using js-ipfs without converting it into Buffer or Readable stream, and it works just fine. since IPFS converts the file into blocks anyway, why use buffer/stream! what are ...
0
votes
1answer
59 views

How to call ERC 721 smart contract methods from JavaScript [duplicate]

I'm trying to create a simple nft minting website and I have my contract working properly but I'm having trouble implementing the actual minting process. So far my site only has the ability to let ...
0
votes
0answers
9 views

function call got a different result on remix and with web3js

i call the exact same function from the exact same contract on remix and got a different result that i had calling it with web3js. Actually remix give me the "good" result. All the others ...
0
votes
1answer
18 views

Accessing Solidity contract member objects from Javascript

I have the following contract defined: pragma solidity >=0.7.0 < 0.9.0; contract LoanApplication { struct Applicant { bytes32 ssn; bool isTenant; } struct Loan ...
0
votes
0answers
25 views

Best approach to transfer a % of a token

i´m very new in blockchain and i'm trying to understand how to handler the amounts and values. I want to transfer 10% of the total token BEP20 amount to an array of wallets. Is this a good way to do ...
0
votes
0answers
25 views

Displayinf error on payable in solc

This is my transaction file, to interact with the Eth blockchain, but it is showing me error in payable keyword in solc, can anyone help me with it, please // SPDX-License-Identifier: UNLICENSED ...
0
votes
1answer
20 views

Differences between .deploy() and deployed() methods

I am writing a js script that deploy my solidity contract. In the tuto, they use two methods .deploy() and .deployed() const main = async () => { const [owner, randomPerson] = await hre.ethers....
1
vote
0answers
28 views

How to get return values from solidity into javascript code?

I have been trying to write different solidity functions inside my smart contract trying to return different types of values: uint256 public _currentTokenId = 0; function getCurrentTokenId() public ...
0
votes
0answers
6 views

How do you get the Erc20 token balance of a random address using hardhat without the ABI json? [duplicate]

I need the dai balance of a whale which I am impersonating with hardhat.
0
votes
1answer
14 views

How to find ERC721 compliant NFTs owned by an address?

Is there any way to get the current owner's address of an nft? I need to use it in my project in unity. I'm new to these things, I would be glad if you could help me.
0
votes
0answers
31 views

Provide button to claim token without showing my private keys

The player will claim their rewards (a token) and pay a fee through their wallet. How does this process happen without my needing to display my private keys on the front-end? What I know so far is ...
0
votes
1answer
158 views

Approve BUSD token in pancakeswap

im new in blockchain and i´m playing with the web3 javascript library. I´m trying to approve the BUSD token to do a swap. My js code is something like this: async function approveToken(web3, c, ...
0
votes
0answers
87 views

How to properly subscribe to Uniswap v3 pool price events with NodeJS and JavaScript?

In reviewing the Uniswap v3 Quoter documentation: These functions are not marked view because they rely on calling non-view functions and reverting to compute the result. They are also not gas ...
0
votes
0answers
27 views

Major differences between ethers-js and ethers-rs

I haven't used ethers-rs before, are there any extra features there compared to ethers-js. Learning rust is not an issue here, I'm pretty comfortable with both javascript and rust.
0
votes
0answers
22 views

Rendering Returned Solidity Mapping Values in React Component

Here is a Solidity contract: pragma solidity ^0.8.7; contract SomeContract { address public manager; uint public theNumberNine; mapping (string => mapping (address => uint)) public ...
1
vote
1answer
80 views

Why can't I access the Uniswap v3 Factory .getPool() function?

As a personal exercise, I am trying to convert the following Uniswap v2 project to Uniswap v3: Uniswap token price monitoring (this is not swapping), i.e. ETH/DAI https://www.youtube.com/watch?v=...
0
votes
0answers
32 views

How to transfer ERC20 Token using web3js

I am trying to send erc20 token using web3js version 1.6.1 but I am getting some strange error , I tried to copy the error from console and paste it in google but I could not find any results this is ...
0
votes
0answers
22 views

Truffle's artifact is undefined when running truffle migrate

I'm trying to run truffle migrate on two js files: 1_initial_migration.js and 2_deploy_contracts.js. I can successfully compile my .sol files to .json ABIs but then when I try to migrate I get the ...
1
vote
1answer
24 views

Is it possible to set listeners on web3js contracts transfer method?

Im trying to transfer erc20 tokens in web3js here is the code I am using let minABI = [ // transfer { "constant": false, "inputs": [ { "name": ...
2
votes
1answer
34 views

Unit testing Solidity JS

I want to test these 3 different require in my mint function with Javascript. function mint(uint256 _mintAmount) public payable { require(_mintAmount > 0, "need to mint at least 1 NFT"...
1
vote
0answers
88 views

How do I generate a metamask mobile deep link programmatically?

I found this site. https://metamask.github.io/metamask-deeplinks/# Which returns a url like: https://metamask.app.link/dapp/tipme.cash However if I change the domain name programmatically it doesn’t ...
1
vote
0answers
46 views

Read from a testnet Rinkeby contract with hardhat script

I am trying to read state variables (using hardhat scripts) from a contract deployed on the Rinkeby network. I use the script below but it returns 'undefined' as if it can't read from the contract. ...
1
vote
0answers
23 views

decode string from smart contract

I have an event that fires from a function which receives a string as parameter, this string is a GUID. However when I use web3.getpastevents it looks like my string(GUID) is encoded as hex, but when ...
0
votes
0answers
5 views

How to deploy a contract with dependencies to other contracts with javascript/web3js in one transaction?

I have a project with 6 contracts and the main one includes the other 5. How do i deploy all of them keeping the dependency but in one single transaction, if possible? I already have their respective ...
0
votes
1answer
16 views

Remix - cant compile for unknown reason

When I compile the program it says it's expecting a ; somewhere in line 8. I've tried adding it in, getting rid of brackets in the line where it's telling me to, but with no avail. Be great if you ...
0
votes
1answer
36 views

Web3js getTransactionCount() always return 1

web3js.eth.getTransactionCount(CONTRACT_ADDRESS+'').then( txcount => { console.log( "-> getTransactionCount: " + txcount ); }); Always return 1, but my contract has lot of ...
0
votes
0answers
15 views

Trouble calling smart contract methods in javascript

I am new to HTML and JavaScript and especially solidity. I am receiving this error - "Uncaught TypeError: VotingContract.returnVoterAddress is not a function". My js script is as follows: if ...

1
2 3 4 5
20