DEFI

How to Build a MultiSig Contract on Tezos | Part 2

The second part of our MultiSig tutorial covers some use cases, and how to write and deploy your first MultiSig contract on Tezos.

By Adebola Adeniran

TRILITECH

550 words, 3 minute read

How to Build Multisig Contract Tezos

In the last tutorial, we looked at what MultiSigs are, some use-cases for them and how to write your first and deploy your first MultiSig contract on Tezos.

In this tutorial, we’ll cover how to write a frontend dApp to interact with a MultiSig contract.

Making Changes to the MultiSig contract #

To get started, we’ll need to make some changes to the contract we deployed in the last tutorial.

In the original smart contract for the MultiSig here, navigate to the test portion of the Smart contract. We’ll change the test_account instances to actual wallet addresses. Change the wallet addresses for alice, bob, charlie and earl to wallet addresses that you control. Later on, you can switch this out for wallet addresses that you’d like as a part of your MultiSig. Like below;

alice = sp.address("tz1_wallet_address")

You may now deploy the updated contract to the Ghostnet.

Writing the Frontend of your Application #

Now, it’s time to build the Frontend dApp for our MultiSig contract to allow users to interact with the contract. This tutorial assumes a good knowledge of React. Knowledge of NextJS is not important.

I like to start with a fresh installation of Tailwind CSS and NextJS. Start off by running the command below in your terminal;

npx create-next-app --tailwind [name-of-your-app]

Follow the prompts to complete the installation.

Installing Dependencies #

We’ll be using a few dependencies to help us along the way;

npm i @taquito/taquito @taquito/beacon-wallet

Styling the App #

You can find all the code for styling the MultiSig dApp we’ll be building in this tutorial here.

Feel free to style the app as you please. If you’re using the styles above, your dApp should now look like below;

Handling App logic with useTaquito #

We’ll set up hooks to handle all of the interaction between our app and Taquito. Hooks allow us to write cleaner and reusable code snippets that we can then use in our components.

Create a useTaquito.ts file in src/hooks.

In this file, we’ll

See the code here

With that done, all we need to is export the methods and states we need and import them into our components.

Reading through the code in src/pages/index.js here shows how to import the methods/state from the useTaquito hooks file and how they’re passed into other components.

We also show different screens based on what menu item the user selects. You should end up with a working app like in this recording.