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.jsonso the imports below work as ESM:
- Configure a
.envfile:
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. Replace0xAddress1 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.

