Last active
March 15, 2023 09:32
-
-
Save adilanchian/71890bf4fcd8f78e94c77cf694b24659 to your computer and use it in GitHub Desktop.
Section 3: Build web3 app that connects to our wallet and talks to our WaveContract
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 React, { useEffect, useState } from "react"; | |
import { ethers } from "ethers"; | |
import './App.css'; | |
import abi from './utils/WavePortal.json'; | |
const App = () => { | |
const [currentAccount, setCurrentAccount] = useState(""); | |
/** | |
* Create a varaible here that holds the contract address after you deploy! | |
*/ | |
const contractAddress = "0xd5f08a0ae197482FA808cE84E00E97d940dBD26E"; | |
const contractABI = abi.abi; | |
const checkIfWalletIsConnected = async () => { | |
try { | |
const { ethereum } = window; | |
if (!ethereum) { | |
console.log("Make sure you have metamask!"); | |
return; | |
} else { | |
console.log("We have the ethereum object", ethereum); | |
} | |
const accounts = await ethereum.request({ method: 'eth_accounts' }); | |
if (accounts.length !== 0) { | |
const account = accounts[0]; | |
console.log("Found an authorized account:", account); | |
setCurrentAccount(account) | |
} else { | |
console.log("No authorized account found") | |
} | |
} catch (error) { | |
console.log(error); | |
} | |
} | |
const connectWallet = async () => { | |
try { | |
const { ethereum } = window; | |
if (!ethereum) { | |
alert("Get MetaMask!"); | |
return; | |
} | |
const accounts = await ethereum.request({ method: "eth_requestAccounts" }); | |
console.log("Connected", accounts[0]); | |
setCurrentAccount(accounts[0]); | |
} catch (error) { | |
console.log(error) | |
} | |
} | |
const wave = async () => { | |
try { | |
const { ethereum } = window; | |
if (ethereum) { | |
const provider = new ethers.providers.Web3Provider(ethereum); | |
const signer = provider.getSigner(); | |
const wavePortalContract = new ethers.Contract(contractAddress, contractABI, signer); | |
let count = await wavePortalContract.getTotalWaves(); | |
console.log("Retrieved total wave count...", count.toNumber()); | |
const waveTxn = await wavePortalContract.wave(); | |
console.log("Mining...", waveTxn.hash); | |
await waveTxn.wait(); | |
console.log("Mined -- ", waveTxn.hash); | |
count = await wavePortalContract.getTotalWaves(); | |
console.log("Retrieved total wave count...", count.toNumber()); | |
} else { | |
console.log("Ethereum object doesn't exist!"); | |
} | |
} catch (error) { | |
console.log(error) | |
} | |
} | |
useEffect(() => { | |
checkIfWalletIsConnected(); | |
}, []) | |
return ( | |
<div className="mainContainer"> | |
<div className="dataContainer"> | |
<div className="header"> | |
👋 Hey there! | |
</div> | |
<div className="bio"> | |
I am farza and I worked on self-driving cars so that's pretty cool right? Connect your Ethereum wallet and wave at me! | |
</div> | |
<button className="waveButton" onClick={wave}> | |
Wave at Me | |
</button> | |
{!currentAccount && ( | |
<button className="waveButton" onClick={connectWallet}> | |
Connect Wallet | |
</button> | |
)} | |
</div> | |
</div> | |
); | |
} | |
export default App |
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
require('@nomiclabs/hardhat-waffle'); | |
module.export = { | |
solidity: '0.8.0', | |
networks: { | |
rinkeby: { | |
url: 'YOUR ALCHEMY_API_URL', | |
accounts: ['YOUR_PRIVATE_RINKEBY_ACCOUNT_KEY'], | |
}, | |
}, | |
}; |
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
{ | |
YOUR_ABI_CONTENT_GOES_HERE | |
} |
Hi, How are you?
Let's discuss it here in detail.
My skype address:
live:.cid.c4858ebe853c8646
Regards.
…On Wed, Mar 15, 2023 at 1:59 AM Apurv Tiwari ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
i got this comment: Error: call revert exception
(method="getTotalWaves()", errorArgs=null, errorName=null,
errorSignature=null, reason=null, code=CALL_EXCEPTION, version=abi/5.5.0)
at Logger.makeError (index.ts:225:28) at Logger.throwError
(index.ts:237:20) at Interface.decodeFunctionResult (interface.ts:425:23)
at Contract. (index.ts:392:44) at Generator.next () at fulfilled
(_version.ts:1:24)
You guys need to change metamask network, to goerli, and it will work !
I did but then also it is not working
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/71890bf4fcd8f78e94c77cf694b24659#gistcomment-4503490>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A3N6YKGBARYOVUBAUBRSXK3W4GAFJBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTCMJZGM4TGNBTU52HE2LHM5SXFJTDOJSWC5DF>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I did but then also it is not working