# Smart Wallet (Vault)

**Ditto offers the enhancement of the ERC4337 with 7579 support via Automate7579 to enable programmable smart account for deferred execution. Our SDK covers the creation of the standardized Smart Wallets with the Ditto Automation Module installed or porting  already existing smart accounts to make them programmable.**

### **Methods**

#### **getNextVaultId**

Retrieves the next available Vault ID for the specified blockchain network. This method is useful for generating a new Vault without conflicts.

```typescript
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.

```typescript
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.

```typescript
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.

```typescript
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.
