an example of how to sign with the frontend and recover/verify signer in YourContract
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
:
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
:
Then, sign the hash using the owner
account:
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):
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!
π πΎ π π₯³ π πΎ π π₯³ π πΎ π π₯³
Learn more about Meta Transactions