🏦 Smart Wallet (Vault)
Methods
getNextVaultId
Retrieves the next available Vault ID for the specified blockchain network. This method is useful for generating a new Vault without conflicts.
const chainId = 1; // Ethereum mainnet
const nextVaultId = await swFactory.getNextVaultId(chainId);
console.log(`Next Vault ID: ${nextVaultId}`);
chainId
: The ID of the blockchain network.
getVaultAddress
Predicts the address of the Vault based on the specified chain ID and Vault ID. This method is useful for knowing the Vault address before actually deploying it.
const chainId = 1; // Ethereum mainnet
const vaultId = 2; // Example Vault ID
const vaultAddress = await swFactory.getVaultAddress(chainId, vaultId);
console.log(`Predicted Vault Address: ${vaultAddress}`);
chainId
: The ID of the blockchain network.vaultId
: The ID of the Vault.
createVault
Creates a new smart wallet (Vault) on the specified blockchain network. This method deploys the Vault contract and returns the deployed Vault instance.
const chainId = 1; // Ethereum mainnet
const nextVaultId = await swFactory.getNextVaultId(chainId);
const vault = await swFactory.createVault(chainId, nextVaultId);
const vaultAddress = vault.getAddress();
console.log(`New Vault Address: ${vaultAddress}`);
chainId
: The ID of the blockchain network.vaultId
: The ID for the new Vault.
getDefaultOrCreate
Retrieves the default Vault for the specified chain ID and account address. If no default Vault exists, it creates a new one.
const chainId = 1; // Ethereum mainnet
const accountAddress = '0xYourAccountAddress';
const vault = await swFactory.getDefaultOrCreate(chainId, accountAddress);
const vaultAddress = vault.getAddress();
console.log(`Default or New Vault Address: ${vaultAddress}`);
chainId
: The ID of the blockchain network.accountAddress
: The account address for which the default Vault is retrieved or created.