Here is an article based on the documentation you provided:
Enabling Multiple Signers in a Vault with Ethereum
In this guide, we will walk through the process of enabling multiple signers in a vault using the @safe-global
library.
Prerequisites
To use multiple signers in your vault, you must first create a new instance of the Safe
class and set the multisig configuration. In this example, we will assume that you are working with a simple multisig configuration 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({
// Set your multisig configuration here
type: 'multiSig',
name: 'My Multisig Test',
publicKey: 'yourPublicKey', // Replace with a valid public key
privateKey: 'yourPrivateKey', // Replace with a valid private key
// Enable multiple signers
enableMultipleSigners: true,
numSigners: {
approvedBySigners: 2, // Number of additional signers allowed to approve transactions
},
});
In this example, we have set 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 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 the initial signer. We can also generate additional signers using the following code:
const { privateKey, publicKey } = wait getPrivateKeyAndPublicKey();
To create a new signer with a specific name and public key, you can use the following code:
const newSigner = wait getNewSigner({
id: 'new-signer',
name: 'John Doe', // Replace with a valid name
publicKey: 'yourPublicKey', // Replace with a valid public key
});
Transmitting signers to the vault
To transmit signers to your vault, you 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 build the transaction
const transaction = new Transaction(signerData, transactionConfig);
return transaction;
};
To pass a signer to our vault, we can create a new transaction and include the signer’s public key:
const mySafeInstance = wait mySafe.createTransaction({
type: 'transaction',
inputs: [],
outputs: [], // Add output if applicable
// 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 vault, you’ll need to create a new instance of the Safe
class, set 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 ‘.
Leave a Reply