Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
21 votes
Accepted

How to convert from Wei to Ether in React?

In web3.js 1.0, use this: web3.utils.fromWei(number [, unit]) doc
xianshenglu's user avatar
21 votes

How to convert from Wei to Ether in React?

I think you're looking for fromWei. In web3.js 0.2x.x: web3.fromWei(n, 'ether')
user19510's user avatar
  • 28.1k
12 votes
Accepted

Module not found: Error: Can't resolve 'stream' in React project including web3

I believe changing react-scripts to 4.0.3 and rerunning yarn install or npm install would've fixed this issue. There are several ways to get around it but I like this way, as you don't have to eject ...
Patrick Rutherford's user avatar
10 votes

Why does sendSignedTransaction return a tx hash BUT does not post to the Rinkeby network (React, Metamask, web3, infura)

This line ... nonce: window.web3.utils.toHex(window.web3.eth.getTransactionCount(fromAccount)), ... relies on a reliable transaction count from Infura. The problem is it's not as reliable (or even ...
Rob Hitchens's user avatar
  • 55.3k
9 votes
Accepted

Comparison of Metamask vs Ganache

Those two products are completely different. Metamask is a blockchain wallet (account management) that secures a private key and helps you to interact with an Ethereum Blockchain network (like ...
Greg Jeanmart's user avatar
7 votes
Accepted

How to import web3 into a React project

It sounds confusing and basing on the version of web3 you have the syntax is different. According to the error you got at the first place seems like you are using web3 1.0. However the instance code ...
qbsp's user avatar
  • 4,367
7 votes
Accepted

What does "on('transactionHash', callback())" do?

Basically .send() function have several stages between start and completion Here are intermediate states sending returns payload: Object: Fired immediately before transmitting the transaction request. ...
Faizan Ul Haq's user avatar
6 votes
Accepted

Why is MeteorJS so popular for making dApps?

There is so much competition in the JavaScript framework space and they are basically all good if you have good command of it ... I think MeteorJS is popular in this space not because it is better ...
Greg Jeanmart's user avatar
6 votes
Accepted

"this._eth.sendTransaction is not a function" when executing method in Web3

You don't need to call the sendTransaction function explicitly, just call the function of your smart-contract like this: contract.buyTicket(3000, { from: '...
Sepultura's user avatar
  • 265
6 votes
Accepted

should I use server side rendering(Next.js) for a dapp?

The big idea behind using the Next.js in ethereum applications (dapps) is server side rendering. You can also use CSR but it will not be good for user experience. Let say you are building an voting ...
Abdullah Aziz's user avatar
6 votes

How to disconnect MetaMask wallet using Web3modal

It's not possible. The connect/disconnect functionality is entirely in the user's hands due to security and privacy concerns. You can only pretend a disconnect by resetting a provider, chainId and ...
Fredo Corleone's user avatar
6 votes
Accepted

How to Calculate APR From A Masterchef Contract Pool

this is the code snippet from the frontend of Pancakeswap, and if I not wrong MasterChef calculates in the same way. /** * Get the APR value in % * @param stakingTokenPrice Token price in the same ...
hack3r-0m's user avatar
  • 1,919
6 votes
Accepted

I am getting error saying export 'ethers'.'provider' (imported as 'ethers') was not found in 'ethers'. Despite importing correctly

use const ethers = require("ethers") instead. it was updated: https://docs.ethers.io/v5/getting-started/
SnowyField's user avatar
5 votes
Accepted

Having issues using the Drizzle library in React

In your index.js file you need to pass drizzle instance into the App component as props: ReactDOM.render(<App drizzle={drizzle} />, document.getElementById("root")); You should also declare ...
Camila's user avatar
  • 66
5 votes
Accepted

Cannot read property 'eth' of undefined

There's a javascript issue in your code: you're using both the web3 injected by metamask (window.web3), and the web3 you're declaring (let web3;). They are both declared in the same scope and that can ...
Tudor Constantin's user avatar
5 votes
Accepted

The send transactions "from" field must be defined!

If you are using accounts[0] as your default account, modify this line: await contract.distributePrizes(); to: await contract.distributePrizes({from: accounts[0]}); Or when you are creating your ...
Fernando Garcia's user avatar
5 votes

Why web3.eth.getAccounts().then(console.log) return empty array?

Later versions of metamask request permission to return the account, so after requesting the accounts metamask extension will popup to ask you for permission in the browser. Another thing I notice ...
Ahmad Altayeb's user avatar
5 votes

Error: Hydration failed because the initial UI does not match what was rendered on the server, Wagmi and Nextjs

If you set autoConnect: to false it should resolve your issue.
Mack's user avatar
  • 51
4 votes
Accepted

TypeError: (intermediate value).at is not a function

Change peopleContract to this: var peopleContract = new ETHEREUM_CLIENT.eth.Contract(peopleContractABI, peopleContractAddress); web3 docs on specifying parameters for your contract object: https://...
atc's user avatar
  • 128
4 votes

How to convert from Wei to Ether in React?

web3.utils.fromWei(yourValue, 'ether') ^^^ You must use the utils library. If you're getting the weird, TypeError: web3.fromWei is not a function and you're trying to console log the output, try ...
Fifth Dimension Dragon's user avatar
4 votes
Accepted

Display Array of struct within array of struct in react

I think you should use await Contract.methods.getPvoteStruct(0,0).call() Also returning arrays from structs is a pain. See web3js.readthedocs.io/en/1.0/web3-eth-contract.html#id12
GrandFleet's user avatar
4 votes

How to mock an ethers provider while testing with jest?

I was running with this problem and you can inject it with ganache-cli const ethereumObject = require("ganache-cli").provider(); You can check out more here: https://michalzalecki.com/integration-...
Cesar's user avatar
  • 211
4 votes
Accepted

Refresh page upon MetaMask Confirmation. Web3js & React()

I added a window.location.reload() after successful transaction (my web3 await function). This works on local test net but will have to do some more digging due to the longer wait times on the Main ...
jaxcoder's user avatar
4 votes
Accepted

How to call a contract function from ReactJS, that takes a struct as an argument?

This depends on your js library that is used to interact with the contract. For Ethers (and probably also web3js) you can either use an object with keys or nested arrays. So for your example: const ...
Richard's user avatar
  • 4,994
4 votes
Accepted

How to detect if user's account on Metamask is disconnected in frontend

There are more events to listen to cover all use cases. In addition, the event subscription and cleanup should be moved into a useEffect in order to stop memory leaks. This is an example that might ...
CaptEmulation's user avatar
4 votes

Warning: Contract code size exceeds 24576 bytes

In your hardhat project folder go to file hardhat.config.js and put the following code in the module.exports module.exports = { solidity: { version: "0.5.15", settings: { optimizer: { ...
Usaudia Khan's user avatar
4 votes
Accepted

window.ethereum.isConnected() always returns true

window.ethereum.isConnected() not refers to connection about user account! In details, this function refers if the provider can make RPC requests to the current chain. From documentation: Note that ...
Antonio Carito's user avatar
3 votes

Build an Ethereum Wallet using React

Basic JavaScript works perfectly fine in React. The most popular Ethereum JS library today seems to be the Web3 JavaScript API. Review their API to find your solutions and specifically balance ...
Shomari's user avatar
  • 625
3 votes
Accepted

Solidity Truffle React TestRPC: Invalid address error while creating transactions through React app

There should be an account address associated to any transaction. While using truffle console, it automatically take the default account but not while using web3. Try to associate an account address ...
Abhishek's user avatar
  • 800
3 votes
Accepted

How to map a web3 to a react.js state

I figured it out by doing the following: const web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545")); const abi = [{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":""...
rstormsf's user avatar
  • 4,357

Only top scored, non community-wiki answers of a minimum length are eligible