Exploring Multisig in ZKsync using Web3.js

Exploring Multisig in ZKsync using Web3.js

In this article, we’ll dive into the multi-sig feature within the ZKsync ecosystem, showing how to deploy and interact with a multi-sig contract. Multisig (multiple signatures) allows for enhanced security by requiring more than one private key to authorize transactions. This is particularly useful for managing funds in a collaborative or highly secure environment.

Prerequisites

Ensure you’ve followed the steps in our earlier articles to set up your local environment and understand the basics of the ZKsync plugin. Before we proceed, ensure you’ve deployed your ZKsync plugin and smart account correctly as outlined previously.

Setting Up the Multi-sig Contract

We start by deploying a multi-sig contract that allows two owners to manage funds. In this example, one owner is created using the private key of an already established account, and the other is randomly generated.

After deploying the contract, we refill the multi-sig wallet and the second owner’s account with Ether.

Executing a Transfer Using Multi-sig account

Once the multi-sig wallet is set up, we can execute a transaction that requires both owners to sign. This involves transferring Ether from the multi-sig account to a recipient’s wallet.

Both owners’ signatures are required to execute this transfer. The recipient’s balance is updated after the transaction, as shown in the output.

Using Paymaster with Multi-sig

In this step, we demonstrate how to make a token transfer using a paymaster. A paymaster can sponsor transactions for users, allowing the use of tokens instead of ETH for transaction fees.

Before executing a transfer, we first send approval tokens to the multi-sig wallet:

We then send ETH using the paymaster:

The transfer is processed, and the paymaster handles the transaction fees using the approval tokens.

Conclusion

In this article, we successfully deployed a multi-sig contract, executed secure transfers, and utilized the paymaster feature for transaction fee sponsorship. Multisig wallets provide a robust solution for managing assets securely with multiple parties.

Next Up: In the upcoming article, we will explore how to work with an injected provider in your DApps, allowing users to interact with blockchain networks directly from their browser extensions like MetaMask. Stay tuned!

Here are the essential links to help you get started:

  • Web3.js Plugin for ZKsync: You can find the official plugin repository here.
  • Examples for Using the Plugin: I've also prepared a dedicated repository with all the code examples from this tutorial and more, which you can access here.
  • ZKsync Web3.js Documentation: For more detailed information and resources, check out the official documentation here.