Skip to content

Commit

Permalink
Multiple accounts under the same owner. (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
y-maghzaz authored Jan 10, 2024
1 parent 11dee91 commit 9f1eedc
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 30 additions & 0 deletions examples/21-get-multiple-accounts.ts
Original file line number Diff line number Diff line change
@@ -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());
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@etherspot/prime-sdk",
"version": "1.4.1",
"version": "1.4.2",
"description": "Etherspot Prime (Account Abstraction) SDK",
"keywords": [
"ether",
Expand Down
1 change: 1 addition & 0 deletions src/sdk/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface SdkOptions {
walletFactoryAddress?: string;
entryPointAddress?: string;
accountAddress?: string;
index?: number;
}

export enum graphqlEndpoints {
Expand Down
8 changes: 7 additions & 1 deletion src/sdk/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [] };

Expand All @@ -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) {
Expand Down Expand Up @@ -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({
Expand All @@ -97,6 +101,7 @@ export class PrimeSdk {
optionsLike,
entryPointAddress,
factoryAddress: walletFactoryAddress,
index: this.index,
})
}
else {
Expand All @@ -107,6 +112,7 @@ export class PrimeSdk {
entryPointAddress,
factoryAddress: walletFactoryAddress,
predefinedAccountAddress: accountAddress,
index: this.index,
})
}
this.bundler = new HttpRpcClient(optionsLike.bundlerRpcUrl, entryPointAddress, chainId);
Expand Down

0 comments on commit 9f1eedc

Please sign in to comment.