import { ethers } from "ethers";
import { SafeFactory } from "@safe-global/safe-core-sdk";
const FACTORY_ADDRESS = "0x914d7Fec6aaC8cd542e72Bca78B30650d45643d7";
/ Using Safe SDK
async function deploySafeWallet(owners, threshold, signer) {
const safeFactory = await SafeFactory.create({
ethAdapter: new EthersAdapter({ ethers, signer }),
safeVersion: '1.4.1'
});
const safeAccountConfig = {
owners: owners,
threshold: threshold,
/ Optional parameters
fallbackHandler: "0x...", / Fallback handler address
paymentToken: ethers.ZeroAddress,
payment: 0,
paymentReceiver: ethers.ZeroAddress
};
/ Predict address before deployment
const predictedAddress = await safeFactory.predictSafeAddress(safeAccountConfig);
console.log("Safe will be deployed to:", predictedAddress);
/ Deploy the Safe
const safeSdk = await safeFactory.deploySafe({ safeAccountConfig });
const safeAddress = await safeSdk.getAddress();
console.log("Safe deployed to:", safeAddress);
return safeSdk;
}
/ Manual deployment without SDK
async function deployManually(signer) {
const factory = new ethers.Contract(
FACTORY_ADDRESS,
["function deploy(bytes,bytes32) returns (address)"],
signer
);
/ Prepare Safe proxy bytecode with initialization
const proxyBytecode = "0x..."; / Safe proxy bytecode
const salt = ethers.id("my-safe-v1");
/ Deploy
const tx = await factory.deploy(proxyBytecode, salt);
const receipt = await tx.wait();
/ Get deployed address from events
const deployedAddress = receipt.logs[0].address;
return deployedAddress;
}