Skip to content

scaffold-eth/scaffold-eth-examples

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ— scaffold-eth - signature recover example

an example of how to sign with the frontend and recover/verify signer in YourContract


quickstart

git clone https://github.com/scaffold-eth/scaffold-eth-examples.git signature-recover

cd signature-recover

git checkout signature-recover
yarn install

you might get node-gyp errors, ignore them and run:

yarn start

in a second terminal window:

yarn chain

in a third terminal window:

yarn deploy

πŸ” Edit your smart contract YourContract.sol in packages/hardhat/contracts

πŸ“ Edit your frontend App.jsx in packages/react-app/src

πŸ“± Open http://localhost:3000 to see the app

On deploy, trasfer the ownership to your frontend address in packages/hardhat/scripts/deploy.js:

image

redeploy your contract so you will be the owner:

yarn deploy

(You can verify the owner in the debug tab)

YourContract should start with 0.1 ETH in it.

Let's sign a message with the owner to send an address some of that ETH in YourContract.

Enter an address and amount to send, then click HASH:

image

Then, sign the hash using the owner account:

image

In a different browser (or incognito), navigate to http://localhost:3000/ and you should have a different address (in the top right).

Give this new address some gas from the faucet.

In the new browser, put in the same to address and value and you should get the same hash:

Instead of signing it with this second account, copy/paste the signature from the owner (previous signature):

image

Click SEND and you should see that the transaction is sent from the non-owner address and is able to send money out of YourContract on behalf of the owner!

image

image

πŸŽ‰ 🍾 🎊 πŸ₯³ πŸŽ‰ 🍾 🎊 πŸ₯³ πŸŽ‰ 🍾 🎊 πŸ₯³

Learn more about Meta Transactions

eth.build video on message signing with a private key

eth.build video on Meta Transactions