Skip to main content
A multi-signature (multi-sig) wallet requires several owners to approve a transaction before it executes. Safe, formerly Gnosis Safe, is the most widely used multi-sig implementation on EVM chains, and its contracts are deployed on peaq. This guide creates a Safe programmatically with the Safe Protocol Kit, adds an owner, and executes a transaction.

Prerequisites

  • Basic knowledge of blockchain development and JavaScript/TypeScript.
  • Familiarity with ethers.js.
  • An RPC URL for the peaq network.
  • Private keys for at least two owners, so you can meet the approval threshold.

Instructions

1. Set up your environment

  • Install the dependencies:
  • Add the following to your package.json so the imports below work as ESM:
  • Configure a .env file:

2. Predict the Safe address

Initialize the Protocol Kit with the owners and the threshold. Safe addresses are deterministic, so you get the address before the Safe exists on chain. Replace 0xAddress1 and 0xAddress2 with the addresses derived from PRIVATE_KEY and SECOND_OWNER_PRIVATE_KEY, so both signing keys belong to owners:

3. Deploy the Safe

createSafeDeploymentTransaction builds the deployment transaction. Send it with your own signer, then connect the Protocol Kit to the deployed address:

4. Add an owner

Adding an owner is a Safe transaction, so it needs the same number of approvals as any other. With a threshold of 2, a second owner signs and the first owner executes:
executeTransaction counts the executing owner’s own approval. If the signatures still fall short of the threshold, it throws There are X signatures missing.

5. Fund the Safe

Send at least 0.1 PEAQ to the Safe before the transfer in the next step. The sending owner also needs PEAQ to pay transaction fees. Using the signer and Safe address from step 3:

6. Execute a transaction

Sending PEAQ out of the funded Safe follows the same pattern:

Summary

You created a Safe on peaq, added an owner, and executed a transfer, all from code. The same Safe can be opened in a front end or driven from a script, and every transaction keeps needing the number of owner approvals you set as the threshold.