Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snippets fixes: Metamask connection, BigNumber #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions LEARN.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,15 @@ Aaaand again, let's handle the logic in ``` handleSubmit ```, change it to the f
async handleSubmit(event) {
event.preventDefault()
const provider = new ethers.providers.Web3Provider(window.ethereum)
await provider.send("eth_requestAccounts", [])
const signer = provider.getSigner()
const contract = new ethers.Contract(
ADDRESS,
ABI,
signer
)
let numberOfTokensToSend = this.state.numOfTokens * (10 ** DECIMALS)
let numberOfTokensToSend =
ethers.BigNumber.from(10).pow(DECIMALS).mul(this.state.numOfTokens)
await contract.transfer(this.state.receiver, numberOfTokensToSend)
}
```
Expand Down Expand Up @@ -409,15 +411,16 @@ In the contract, we require that a user sends 1 Gwei to call ``` buy ```. How to
async handleSubmit(event) {
event.preventDefault()
const provider = new ethers.providers.Web3Provider(window.ethereum)
await provider.send("eth_requestAccounts", [])
const signer = provider.getSigner()
const contract = new ethers.Contract(
ADDRESS,
ABI,
signer
)
let numberOfTokensToBuy = this.state.numOfTokens * (10 ** DECIMALS)
let numberOfTokensToBuy = ethers.BigNumber.from(10).pow(DECIMALS).mul(this.state.numOfTokens)
const overrides = {
value: ethers.utils.parseEther("0.000000001")
value: ethers.utils.parseEther("0.000000001").mul(this.state.numOfTokens)
}
await contract.buy(numberOfTokensToBuy, overrides)
}
Expand Down