GithubHelp home page GithubHelp logo

route-2 / challenge-5-multisig Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 725 KB

License: MIT License

Dockerfile 1.16% Shell 4.49% JavaScript 89.28% Solidity 3.20% HTML 0.88% CSS 0.07% Less 0.44% TypeScript 0.47%

challenge-5-multisig's Introduction

๐Ÿ— scaffold-eth | ๐Ÿฐ BuidlGuidl

๐Ÿšฉ Challenge 5 - Multisig ๐Ÿ‘›

๐Ÿ‘‡๐Ÿผ Quick Break-Down ๐Ÿ‘›

This is a smart contract that acts as an off-chain signature-based shared wallet amongst different signers that showcases use of meta-transaction knowledge and ECDSA recover(). If you are looking for the challenge, go to the challenges repo within scaffold-eth!

If you are unfamiliar with these concepts, check out all the ETH.BUILD videos by Austin Griffith, especially the Meta Transactions one!

At a high-level, the contract core functions are carried out as follows:

Off-chain: โ›“๐Ÿ™…๐Ÿปโ€โ™‚๏ธ - Generation of a packed hash (bytes32) for a function call with specific parameters through a public view function . - It is signed by one of the signers associated to the multisig, and added to an array of signatures (bytes[] memory signatures)

On-Chain: โ›“๐Ÿ™†๐Ÿปโ€โ™‚๏ธ

  • bytes[] memory signatures is then passed into executeTransaction as well as the necessary info to use recover() to obtain the public address that ought to line up with one of the signers of the wallet.
    • This method, plus some conditional logic to avoid any duplicate entries from a single signer, is how votes for a specific transaction (hashed tx) are assessed.
  • If it's a success, the tx is passed to the call(){} function of the deployed MetaMultiSigWallet contract (this contract), thereby passing the onlySelf modifier for any possible calls to internal txs such as (addSigner(),removeSigner(),transferFunds(),updateSignaturesRequried()).

Cool Stuff that is Showcased: ๐Ÿ˜Ž

  • NOTE: Showcases how the call(){} function is an external call that ought to increase the nonce of an external contract, as they increment differently from user accounts.
  • Normal internal functions, such as changing the signers, and adding or removing signers, are treated as external function calls when call() is used with the respective transaction hash.
  • Showcases use of an array (see constructor) populating a mapping to store pertinent information within the deployed smart contract storage location within the EVM in a more efficient manner.

๐Ÿƒโ€โ™€๏ธ Quick Start

required: Node plus Yarn and Git

git clone https://github.com/scaffold-eth/scaffold-eth-challenges challenge-5-multisig

cd challenge-5-multisig

git checkout challenge-5-multisig
yarn install
yarn chain

in a second terminal window:

cd challenge-5-multisig
yarn start

๐Ÿ” Edit your smart contract MultiSigWallet.sol in packages/hardhat/contracts

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

๐Ÿ’ผ Edit your deployment script deploy.js in packages/hardhat/scripts

๐Ÿ“ฑ Open http://localhost:3000 to see the app

in a third terminal window:

yarn backend

๐Ÿ”ง Configure your deployment in packages/hardhat/scripts/deploy.js

Edit the chainid, your owner addresses, and the number of signatures required:

image

in a fourth terminal deploy with your frontend address as one of the owners:

yarn deploy

Use the faucet wallet to send your multi-sig contract some funds:

image

To add new owners, use the "Owners" tab:

image

This will take you to a populated transaction create page:

image

Create & sign the new transaction:

image

You will see the new transaction in the pool (this is all off-chain):

image

Click on the ellipsses button [...] to read the details of the transaction

image

Give your account some gas at the faucet and execute the transaction

The transction will appear as "executed" on the front page:

image

Create a transaction to send some funds to your frontend account:

image

This time we will need a second signature:

image

Sign the transacton with enough owners: image

(You'll notice you don't need โ›ฝ๏ธgas to sign transactions.)

Execute the transction to transfer the funds:

image

(You might need to trigger a new block by sending yourself some faucet funds or something. HartHat blocks only get mined when there is a transaction.)

๐Ÿ’ผ Edit your deployment script deploy.js in packages/hardhat/scripts

๐Ÿ” Edit your contracts form, MetaMultiSigWallet.sol in packages/hardhat/contracts

๐Ÿ“ Edit your frontend in packages/react-app/src/views

โš”๏ธ Side Quests

๐ŸŸ Create custom signer roles for your Wallet

You may not want every signer to create new transfers, only allow them to sign existing transactions or a mega-admin role who will be able to veto any transaction.

๐Ÿ˜Ž Integrate this MultiSig wallet into other branches like nifty-ink

Make a MultiSig wallet to store your precious doodle-NFTs!?


๐Ÿ“ก Deploy the wallet!

๐Ÿ›ฐ Ready to deploy to a testnet?

Change the defaultNetwork in packages/hardhat/hardhat.config.js

image

๐Ÿ” Generate a deploy account with yarn generate

image

๐Ÿ‘› View your deployer address using yarn account (You'll need to fund this account. Hint: use an instant wallet to fund your account via QR code)

image

๐Ÿ‘จโ€๐ŸŽค Deploy your wallet:

yarn deploy

โœ๏ธ Edit your frontend App.jsx in packages/react-app/src to change the targetNetwork to wherever you deployed your contract:

image

You should see the correct network in the frontend:

image

Also change the poolServerUrl constant to your deployed backend (via yarn backend)

image

Alternatively you can use the pool server url in the above screenshot


๐Ÿ”ถ Infura

You will need to get a key from infura.io and paste it into constants.js in packages/react-app/src:

image


๐Ÿ›ณ Ship the app!

โš™๏ธ build and upload your frontend and share the url with your friends...

# build it:

yarn build

# upload it:

yarn surge

OR

yarn s3

OR

yarn ipfs

image

๐Ÿ‘ฉโ€โค๏ธโ€๐Ÿ‘จ Share your public url with friends, add signers and send some tasty ETH to a few lucky ones ๐Ÿ˜‰!!

(Written by: @umphams)

๐Ÿ’ฌ Support Chat

Join the telegram support chat ๐Ÿ’ฌ to ask questions and find others building with ๐Ÿ— scaffold-eth!


๐Ÿ™ Please check out our Gitcoin grant too!

challenge-5-multisig's People

Contributors

route-2 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.