Here’s an article based on the documentation you provided:
Enabling Multiple Signers in a Safe with Ethereum
In this guide, we’ll walk through the process of enabling multiple signers within a safe using the @safe-global
library.
Prerequisites
To use multiple signers in your safe, you first need to create a new instance of the Safe
class and define the multisig configuration. In this example, we’ll assume that you’re working with a simple multisig setup where one signer can approve two additional signers.
First, make sure to install the required library:
npm install @safe-global
Creating a New Safe Instance
Create a new file called safe.js
and add the following code to define your safe instance:
import { Safe } from '@safe-global';
const mySafe = new Safe({
// Define your multisig configuration here
type: 'multiSig',
name: 'My Multisig Test',
publicKey: 'yourPublicKey', // Replace with a valid publicKey
privateKey: 'yourPrivateKey', // Replace with a valid privateKey
// Enable multiple signers
enableMultipleSigners: true,
numSigners: {
approvedBySigners: 2, // Number of additional signers allowed to approve transactions
},
});
In this example, we’ve defined a multisig configuration for our safe with numSigners
set to {approvedBySigners: 2}
. This means that one signer (the creator of the safe) can approve two additional signers.
Creating Signers
To create multiple signers, you’ll need to generate new signing keys and add them to your wallet or a secure storage solution like a hardware wallet.
For this example, let’s assume we have a private key called privateKey
that we’ll use as our initial signer. We can also generate additional signers using the following code:
const { privateKey, publicKey } = await getPrivateKeyAndPublicKey();
To create a new signer with a specific name and public key, you can use the following code:
const newSigner = await getNewSigner({
id: 'new-signer',
name: 'John Doe', // Replace with a valid name
publicKey: 'yourPublicKey', // Replace with a valid publicKey
});
Passing Signers to the Safe
To pass signers to your safe, you’ll need to create a new transaction that includes the necessary information (e.g., signer names and public keys). In this example, let’s assume we have a simple createTransaction
function:
const createTransaction = async (transactionConfig) => {
const signerData = await getSignerInfo(transactionConfig.signers);
// Use the signer data to construct the transaction
const transaction = new Transaction(signerData, transactionConfig);
return transaction;
};
To pass a signer to our safe, we can create a new transaction and include the signer’s public key:
const mySafeInstance = await mySafe.createTransaction({
type: 'transaction',
inputs: [],
outputs: [], // Add output if any
// Include a signer in the transaction
signers: [newSigner.publicKey],
});
In this example, we’ve created a new transaction and included our newSigner
public key as one of the signers. This will allow us to approve transactions with multiple signers.
Putting it all together
To use multiple signers in your safe, you’ll need to create a new instance of the Safe
class, define the multisig configuration, and then create multiple signers using the code above. Here’s an example of how you can put it all together:
“`javascript
import { Safe } from ‘@safe-global’;
import getPrivateKeyAndPublicKey from ‘./getPrivateKeyAndPublicKey’;
import { createTransaction } from ‘.