Questions tagged [ethers.js]

Ethers.js is a JavaScript framework to interact with EVM smart contracts.

More information on ethers.io.

801 questions
4
votes
1 answer

How to establish a web3 provider connection from a Vue.js DApp?

I am intended to interact with Rootstock blockchain from a vue.js DApp to track wallet balance and send RBTC. ​ I want to establish a Metamask connection and use ethers.js web3 provider to interact with the Rootstock network. ​ I created a Pinia…
Irene Patrikios
  • 249
  • 1
  • 5
4
votes
0 answers

ethers: processing response error code -32000, SERVER_ERROR on BSC testnet while trying to approve on MetaMask

I am trying to get MetaMask to popup to approve a dapp to use my erc20 tokens like: const provider = new ethers.providers.JsonRpcProvider(url); // url === bsc testnet rpc const erco20Contract = new ethers.Contract( erco20ContractAddress, …
sdfsdf
  • 5,052
  • 9
  • 42
  • 75
4
votes
1 answer

How to use hardhat with ES module?

I wanted to add hardhat to a project that uses ES modules. Hardhat complains that I can't use require in the hardhat.config.js file, so I renamed it to import, but it still won't compile with the following error: require() of ES modules is not…
Abdi mussa
  • 171
  • 11
4
votes
3 answers

Hardhat – What are the strange calls to my smart contract?

I am using Hardhat hackathon boilerplate and calling my smart contract's (address 1c0, addresses shortened for clarity) function MyContract#addProduct from the UI via ethers.js. The problem: I see bunch of weird function calls before and after I…
TechGeorgii
  • 414
  • 4
  • 14
4
votes
3 answers

How to get the returned data from a smart contract function using ethers.js?

I'm trying to consume a function from a smart contract using ethers.js. The function retrieve the info of a user logged before (with the help of other function). This is the function snippet. function getUser(address _userAddress) public …
4
votes
3 answers

Ethers.js returns the same wallet address even if I switch accounts

I'm using Ethers.js to allow users to connect their Metamask wallets to my app. Here's the code that I have: import { ethers } from "ethers" async function connect() { const provider = new ethers.providers.Web3Provider(window.ethereum, "any") …
Yulian
  • 6,262
  • 10
  • 65
  • 92
4
votes
1 answer

How do I reset Hardhat's mainnet fork between tests?

I'm writing unit tests in Hardhat using Hardhat's mainnet fork, however it seems that the results from one test are affecting future tests and causing my assertions to fail. I'm forking using Alchemy and from block #14189520. For example: it("Test…
Jasperan
  • 2,154
  • 1
  • 16
  • 40
4
votes
1 answer

Estimate gas prices with Ethers JS

I am trying to make a simple js bot that checks every block for eth(or the main token of the chain) and sends it to another wallet. I have a working bot: const { ethers } = require('ethers') const provider = new…
owenk455
  • 43
  • 1
  • 3
4
votes
1 answer

Uniswap getAmountsOut() rounds value down to nearest Ether

I'm calling getAmountsOut() from the UniswapV2Router02 contract using ethers.js, where I'm checking the amount of ETH I can get for 50000 DAI. Using the below code, the output amount tells me I can currently get exactly 15 ETH. For testing purposes…
Jasperan
  • 2,154
  • 1
  • 16
  • 40
4
votes
2 answers

Override the gasPrice in ethers.js contract interaction

How can I set the gasPrice in a contract interaction using ethers.js? I'm trying to override the gasPrice in the code below: let txPromise = contract.populateTransaction.runAdventureVRF(0, false, { gasPrice: 800000…
user2954587
  • 4,661
  • 6
  • 43
  • 101
4
votes
1 answer

web3-react error: Web3ReactProvider not calling getLibrary function

I have this issue on a simple react app. I am trying to connect to metamask using a "Connect" button, but when i click that button the console shows an error saying "Error: Invariant failed: No found." As you can see, I…
Ignacio Feito
  • 41
  • 1
  • 2
4
votes
1 answer

Ether.js works fine on desktop but not with metamask app (android/ios)

I noticed that my little vanilla JS script to get people to connect to my "dapp" works fine on desktop with metamask, but doesn't work with metamask mobile app. It gives me an error as if the "Provider" was not set. const provider = new…
Tryneed
  • 65
  • 3
4
votes
1 answer

Use a Waffle mock contract as a callee of a method in a unit test

Problem: I want to test that a method is only callable by another contract. Example: // B.sol contract B { A _a; uint256 i; constructor(A a) { _a = a; i = 0; } function doSomething() external { require(address(_a) ==…
Dzuray
  • 43
  • 5
4
votes
1 answer

Use reactnnative walletconnect with ether.js

This is a rough summary since these things exist in different views. I have a react native app that uses wallet connect. this allows me to connect to a meta mask wallet on my phone and creates a connector instance. import { useWalletConnect, …
Heyrio
  • 129
  • 2
  • 11
4
votes
1 answer

Get require() message error from a smart contract in Ethereum

I'm starting to learn Solidity and how to interact with smart contracts within a Dapp, and I would like to know how can I log/handle errors from the contract in my Dapp. For example, in the Dapp I have a button, when you click it, it runs a function…