diff --git a/CHANGELOG.md b/CHANGELOG.md index fea4f48d..a6e04071 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +## [1.4.2] - 2024-01-09 +### New +- Integrate index nonce in sdkOptions for enabling the creation of multiple accounts under the same owner. + ## [1.4.1] - 2023-12-27 ### Bug Fixes - Added an optional parameter called accountAddress in SDKOptions to specify the contract address they wish to connect and added checks to verify that. This one is for users who changed the owner of the contract address diff --git a/examples/21-get-multiple-accounts.ts b/examples/21-get-multiple-accounts.ts new file mode 100644 index 00000000..57696c84 --- /dev/null +++ b/examples/21-get-multiple-accounts.ts @@ -0,0 +1,30 @@ +import { PrimeSdk } from '../src'; +import * as dotenv from 'dotenv'; + +dotenv.config(); + +async function main() { + // initializating sdk for index 0... + const primeSdk = new PrimeSdk( + { privateKey: process.env.WALLET_PRIVATE_KEY }, + { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' }, + ); + + // get EtherspotWallet address for index 0... + const address: string = await primeSdk.getCounterFactualAddress(); + console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet address for index 0: ${address}`); + + // initializating sdk for index 1... + const primeSdk1 = new PrimeSdk( + { privateKey: process.env.WALLET_PRIVATE_KEY }, + { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', index: 1 }, + ); + + // get EtherspotWallet address for index 1... + const address1: string = await primeSdk1.getCounterFactualAddress(); + console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet address for index 1: ${address1}`); +} + +main() + .catch(console.error) + .finally(() => process.exit()); diff --git a/package.json b/package.json index e32cf31e..39a01c4b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@etherspot/prime-sdk", - "version": "1.4.1", + "version": "1.4.2", "description": "Etherspot Prime (Account Abstraction) SDK", "keywords": [ "ether", diff --git a/src/sdk/interfaces.ts b/src/sdk/interfaces.ts index d21aed13..818c46b6 100644 --- a/src/sdk/interfaces.ts +++ b/src/sdk/interfaces.ts @@ -22,6 +22,7 @@ export interface SdkOptions { walletFactoryAddress?: string; entryPointAddress?: string; accountAddress?: string; + index?: number; } export enum graphqlEndpoints { diff --git a/src/sdk/sdk.ts b/src/sdk/sdk.ts index 9f3da8ce..05149196 100644 --- a/src/sdk/sdk.ts +++ b/src/sdk/sdk.ts @@ -31,6 +31,7 @@ export class PrimeSdk { private bundler: HttpRpcClient; private chainId: number; private factoryUsed: Factory; + private index: number; private userOpsBatch: BatchUserOpsRequest = { to: [], data: [], value: [] }; @@ -44,12 +45,14 @@ export class PrimeSdk { } const { - chainId, // + index, + chainId, rpcProviderUrl, accountAddress, } = optionsLike; this.chainId = chainId; + this.index = index ?? 0; const networkConfig = getNetworkConfig(chainId); if (!optionsLike.bundlerRpcUrl) { @@ -89,6 +92,7 @@ export class PrimeSdk { optionsLike, entryPointAddress, factoryAddress: walletFactoryAddress, + index: this.index, }) } else if (this.factoryUsed === Factory.SIMPLE_ACCOUNT) { this.etherspotWallet = new SimpleAccountAPI({ @@ -97,6 +101,7 @@ export class PrimeSdk { optionsLike, entryPointAddress, factoryAddress: walletFactoryAddress, + index: this.index, }) } else { @@ -107,6 +112,7 @@ export class PrimeSdk { entryPointAddress, factoryAddress: walletFactoryAddress, predefinedAccountAddress: accountAddress, + index: this.index, }) } this.bundler = new HttpRpcClient(optionsLike.bundlerRpcUrl, entryPointAddress, chainId);