Last active
December 13, 2021 17:03
-
-
Save GeoffMahugu/22e639b244bf25454259d119116ffd1c to your computer and use it in GitHub Desktop.
This is the transact function for react web3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Import useState from react | |
import { useState } from "react"; | |
function App() { | |
// Add minting toggle listener | |
const [minting, setMinting] = useState(false); | |
// Minting Function | |
async function mint() { | |
setMinting(true); | |
const myAccount = "0x391EC0c94451e924C76a2B1ffc08268823f094e5"; //Account to receive payment | |
const price = "0.01"; // This is the price in ETH | |
let obj = { | |
to: myAccount, | |
from: account, | |
value: web3.utils.toWei(price, "ether"), // Needs to be converted to Wei units | |
gas: 85000, // Eth ⛽ price | |
gasLimit: "100000" | |
}; | |
await library.eth.sendTransaction(obj, async (e, tx) => { | |
if (e) { | |
alert(`Something went wrong! Try switching accounts - ${e}`); | |
console.log("ERROR->", e); | |
setMinting(false); | |
} else { | |
setMinting(false); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment