From 0d85cdf2e9958f3a3a7bba16e36ca139fc7c926d Mon Sep 17 00:00:00 2001 From: Vignesh Date: Tue, 30 Jan 2024 13:45:04 +0530 Subject: [PATCH 1/7] added optional parameter for bundler api key --- examples/23-bundlerApiKey.ts | 18 ++++++++++++++++++ src/sdk/interfaces.ts | 3 ++- src/sdk/network/constants.ts | 26 +++++++++++++------------- src/sdk/sdk.ts | 5 +++-- 4 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 examples/23-bundlerApiKey.ts diff --git a/examples/23-bundlerApiKey.ts b/examples/23-bundlerApiKey.ts new file mode 100644 index 00000000..7a88880d --- /dev/null +++ b/examples/23-bundlerApiKey.ts @@ -0,0 +1,18 @@ +import { PrimeSdk } from '../src'; +import * as dotenv from 'dotenv'; + +dotenv.config(); + + +async function main() { + // initializating sdk... + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', etherspotBundlerApiKey: '' }) + + // get EtherspotWallet address... + const address: string = await primeSdk.getCounterFactualAddress(); + console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet address: ${address}`); +} + +main() + .catch(console.error) + .finally(() => process.exit()); diff --git a/src/sdk/interfaces.ts b/src/sdk/interfaces.ts index 818c46b6..663627a4 100644 --- a/src/sdk/interfaces.ts +++ b/src/sdk/interfaces.ts @@ -13,11 +13,12 @@ export enum Factory { export interface SdkOptions { chainId: number; + projectKey: string; stateStorage?: StateStorage; bundlerRpcUrl?: string; rpcProviderUrl?: string; graphqlEndpoint?: string; - projectKey: string; + etherspotBundlerApiKey?: string; factoryWallet?: Factory; walletFactoryAddress?: string; entryPointAddress?: string; diff --git a/src/sdk/network/constants.ts b/src/sdk/network/constants.ts index 029e0cc1..d7f042b2 100644 --- a/src/sdk/network/constants.ts +++ b/src/sdk/network/constants.ts @@ -147,7 +147,7 @@ export const Networks: { }, [10]: { chainId: 10, - bundler: 'https://optimism-bundler.etherspot.io', + bundler: 'https://rpc.etherspot.io/optimism?api-key=', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -160,7 +160,7 @@ export const Networks: { }, [137]: { chainId: 137, - bundler: 'https://polygon-bundler.etherspot.io', + bundler: 'https://rpc.etherspot.io/polygon?api-key=', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -173,7 +173,7 @@ export const Networks: { }, [42161]: { chainId: 42161, - bundler: 'https://arbitrum-bundler.etherspot.io', + bundler: 'https://rpc.etherspot.io/arbitrum?api-key=', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -199,7 +199,7 @@ export const Networks: { }, [1]: { chainId: 1, - bundler: 'https://ethereum-bundler.etherspot.io/', + bundler: 'https://rpc.etherspot.io/ethereum?api-key=', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -238,7 +238,7 @@ export const Networks: { }, [122]: { chainId: 122, - bundler: 'https://fuse-bundler.etherspot.io', + bundler: 'https://rpc.etherspot.io/fuse?api-key=', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -264,7 +264,7 @@ export const Networks: { }, [100]: { chainId: 100, - bundler: 'https://gnosis-bundler.etherspot.io/', + bundler: 'https://rpc.etherspot.io/gnosis?api-key=', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -329,7 +329,7 @@ export const Networks: { }, [5000]: { chainId: 5000, - bundler: 'https://mantle-bundler.etherspot.io/', + bundler: 'https://rpc.etherspot.io/mantle?api-key=', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -355,7 +355,7 @@ export const Networks: { }, [43114]: { chainId: 43114, - bundler: 'https://avalanche-bundler.etherspot.io/', + bundler: 'https://rpc.etherspot.io/avalanche?api-key=', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -368,7 +368,7 @@ export const Networks: { }, [8453]: { chainId: 8453, - bundler: 'https://base-bundler.etherspot.io/', + bundler: 'https://rpc.etherspot.io/base?api-key=', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -381,7 +381,7 @@ export const Networks: { }, [56]: { chainId: 56, - bundler: 'https://bnb-bundler.etherspot.io/', + bundler: 'https://rpc.etherspot.io/bnb?api-key=', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -420,7 +420,7 @@ export const Networks: { }, [59144]: { chainId: 59144, - bundler: 'https://linea-bundler.etherspot.io/', + bundler: 'https://rpc.etherspot.io/linea?api-key=', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -459,7 +459,7 @@ export const Networks: { }, [14]: { chainId: 14, - bundler: 'https://flare-bundler.etherspot.io/', + bundler: 'https://rpc.etherspot.io/flare?api-key=', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -485,7 +485,7 @@ export const Networks: { }, [534352]: { chainId: 534352, - bundler: 'https://scroll-bundler.etherspot.io/', + bundler: 'https://rpc.etherspot.io/scroll?api-key=', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { diff --git a/src/sdk/sdk.ts b/src/sdk/sdk.ts index e012a208..1fc9faf6 100644 --- a/src/sdk/sdk.ts +++ b/src/sdk/sdk.ts @@ -49,6 +49,7 @@ export class PrimeSdk { chainId, rpcProviderUrl, accountAddress, + etherspotBundlerApiKey, } = optionsLike; this.chainId = chainId; @@ -56,8 +57,8 @@ export class PrimeSdk { const networkConfig = getNetworkConfig(chainId); if (!optionsLike.bundlerRpcUrl) { - if (!networkConfig) throw new Exception('No bundler Rpc provided'); - optionsLike.bundlerRpcUrl = networkConfig.bundler; + if (!networkConfig || networkConfig.bundler == '') throw new Exception('No bundler Rpc provided'); + optionsLike.bundlerRpcUrl = `${networkConfig.bundler.includes("?api-key=") ? networkConfig.bundler + etherspotBundlerApiKey : networkConfig.bundler}`; } if (networkConfig) { From 8999d2a4b3c32afa160f364dfbf7785f1f7ea921 Mon Sep 17 00:00:00 2001 From: Vignesh Date: Tue, 30 Jan 2024 13:47:15 +0530 Subject: [PATCH 2/7] updated package version --- CHANGELOG.md | 4 ++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf727c87..4caff48b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +## [1.4.3] - 2024-01-30 +### New +- Added `etherspotBundlerApiKey` optional parameter in SdkOptions for use of predefined mainnet bundlers + ## [1.4.2] - 2024-01-26 ### Breaking changes - Refactored `estimate` method diff --git a/package-lock.json b/package-lock.json index eb854407..e3a6e62c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@etherspot/prime-sdk", - "version": "1.4.1", + "version": "1.5.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@etherspot/prime-sdk", - "version": "1.4.1", + "version": "1.5.1", "license": "MIT", "dependencies": { "@apollo/client": "3.8.7", diff --git a/package.json b/package.json index 1b4ec2d4..cafc63bc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@etherspot/prime-sdk", - "version": "1.5.0", + "version": "1.5.1", "description": "Etherspot Prime (Account Abstraction) SDK", "keywords": [ "ether", From 0a69088d4eacbf77fc68ecabffe91ab05f212536 Mon Sep 17 00:00:00 2001 From: Vignesh Date: Thu, 1 Feb 2024 14:51:25 +0530 Subject: [PATCH 3/7] changed as per feedback --- CHANGELOG.md | 2 +- examples/01-get-address.ts | 4 +-- examples/02-transfer-funds.ts | 4 +-- examples/03-transfer-erc20.ts | 4 +-- examples/04-transfer-nft.ts | 4 +-- examples/12-add-guardians.ts | 4 +-- examples/13-paymaster.ts | 3 ++- examples/14-zeroDev-address.ts | 6 +++-- examples/15-simpleAccount-address.ts | 6 +++-- examples/16-paymaster-arka.ts | 3 ++- .../19-paymaster-validUntil-validAfter.ts | 4 +-- examples/20-callGasLimit.ts | 6 +++-- examples/21-get-multiple-accounts.ts | 6 ++--- examples/22-concurrent-userops.ts | 6 +++-- examples/23-bundlerApiKey.ts | 7 +++-- src/sdk/base/BaseAccountAPI.ts | 6 ++--- src/sdk/bundler/index.ts | 2 ++ src/sdk/bundler/interface.ts | 6 +++++ src/sdk/bundler/providers/EtherspotBundler.ts | 18 +++++++++++++ src/sdk/bundler/providers/GenericBundler.ts | 9 +++++++ src/sdk/bundler/providers/index.ts | 2 ++ src/sdk/index.ts | 1 + src/sdk/interfaces.ts | 3 ++- src/sdk/network/constants.ts | 26 +++++++++---------- src/sdk/sdk.ts | 11 +++----- 25 files changed, 99 insertions(+), 54 deletions(-) create mode 100644 src/sdk/bundler/index.ts create mode 100644 src/sdk/bundler/interface.ts create mode 100644 src/sdk/bundler/providers/EtherspotBundler.ts create mode 100644 src/sdk/bundler/providers/GenericBundler.ts create mode 100644 src/sdk/bundler/providers/index.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 4caff48b..9ce561f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # Changelog ## [1.4.3] - 2024-01-30 ### New -- Added `etherspotBundlerApiKey` optional parameter in SdkOptions for use of predefined mainnet bundlers +- Added `GenericBundler` and `EtherspotBundler` as bundlerProviders and removed bundlerUrl params from SdkOptions ## [1.4.2] - 2024-01-26 ### Breaking changes diff --git a/examples/01-get-address.ts b/examples/01-get-address.ts index 6e09f902..a9610b09 100644 --- a/examples/01-get-address.ts +++ b/examples/01-get-address.ts @@ -1,4 +1,4 @@ -import { PrimeSdk } from '../src'; +import { EtherspotBundler, PrimeSdk } from '../src'; import * as dotenv from 'dotenv'; dotenv.config(); @@ -6,7 +6,7 @@ dotenv.config(); async function main() { // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' }) + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), '') }) // Testnets dont need apiKey on bundlerProvider // get EtherspotWallet address... const address: string = await primeSdk.getCounterFactualAddress(); diff --git a/examples/02-transfer-funds.ts b/examples/02-transfer-funds.ts index 6e34b072..3dece46c 100644 --- a/examples/02-transfer-funds.ts +++ b/examples/02-transfer-funds.ts @@ -1,5 +1,5 @@ import { ethers } from 'ethers'; -import { PrimeSdk } from '../src'; +import { EtherspotBundler, PrimeSdk } from '../src'; import { printOp } from '../src/sdk/common/OperationUtils'; import * as dotenv from 'dotenv'; import { sleep } from '../src/sdk/common'; @@ -11,7 +11,7 @@ const value = '0.00001'; // transfer value async function main() { // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' }) + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/03-transfer-erc20.ts b/examples/03-transfer-erc20.ts index d5502798..f2720d61 100644 --- a/examples/03-transfer-erc20.ts +++ b/examples/03-transfer-erc20.ts @@ -1,5 +1,5 @@ import { ethers } from 'ethers'; -import { PrimeSdk } from '../src'; +import { EtherspotBundler, PrimeSdk } from '../src'; import { printOp } from '../src/sdk/common/OperationUtils'; import { ERC20_ABI } from '../src/sdk/helpers/abi/ERC20_ABI'; import * as dotenv from 'dotenv'; @@ -14,7 +14,7 @@ const tokenAddress = '0x326C977E6efc84E512bB9C30f76E30c160eD06FB'; async function main() { // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' }) + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/04-transfer-nft.ts b/examples/04-transfer-nft.ts index 2a2efb23..902e1211 100644 --- a/examples/04-transfer-nft.ts +++ b/examples/04-transfer-nft.ts @@ -1,5 +1,5 @@ import { ethers } from 'ethers'; -import { PrimeSdk } from '../src'; +import { EtherspotBundler, PrimeSdk } from '../src'; import { printOp } from '../src/sdk/common/OperationUtils'; import * as dotenv from 'dotenv'; import { sleep } from '../src/sdk/common'; @@ -13,7 +13,7 @@ const tokenId = 4; async function main() { // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' }) + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/12-add-guardians.ts b/examples/12-add-guardians.ts index 590e284c..24e7cd9d 100644 --- a/examples/12-add-guardians.ts +++ b/examples/12-add-guardians.ts @@ -1,5 +1,5 @@ import { ethers } from 'ethers'; -import { PrimeSdk } from '../src'; +import { EtherspotBundler, PrimeSdk } from '../src'; import { printOp } from '../src/sdk/common/OperationUtils'; import * as dotenv from 'dotenv'; import { sleep } from '../src/sdk/common'; @@ -10,7 +10,7 @@ async function main() { // initializating sdk... const primeSdk = new PrimeSdk( { privateKey: process.env.WALLET_PRIVATE_KEY }, - { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' }, + { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) }, ); console.log('address: ', primeSdk.state.EOAAddress); diff --git a/examples/13-paymaster.ts b/examples/13-paymaster.ts index 4096747a..012d0796 100644 --- a/examples/13-paymaster.ts +++ b/examples/13-paymaster.ts @@ -1,5 +1,5 @@ import { ethers } from 'ethers'; -import { PrimeSdk } from '../src'; +import { EtherspotBundler, PrimeSdk } from '../src'; import { printOp } from '../src/sdk/common/OperationUtils'; import * as dotenv from 'dotenv'; import { sleep } from '../src/sdk/common'; @@ -14,6 +14,7 @@ async function main() { // initializating sdk... const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', + bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/14-zeroDev-address.ts b/examples/14-zeroDev-address.ts index dd72b2c0..03006bf6 100644 --- a/examples/14-zeroDev-address.ts +++ b/examples/14-zeroDev-address.ts @@ -1,4 +1,4 @@ -import { Factory, PrimeSdk } from '../src'; +import { EtherspotBundler, Factory, PrimeSdk } from '../src'; import * as dotenv from 'dotenv'; dotenv.config(); @@ -6,7 +6,9 @@ dotenv.config(); async function main() { // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', factoryWallet: Factory.ZERO_DEV }) + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', factoryWallet: Factory.ZERO_DEV, + bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) + }) // get ZeroDev address... const address: string = await primeSdk.getCounterFactualAddress(); diff --git a/examples/15-simpleAccount-address.ts b/examples/15-simpleAccount-address.ts index 0bca7475..7a95a8cc 100644 --- a/examples/15-simpleAccount-address.ts +++ b/examples/15-simpleAccount-address.ts @@ -1,4 +1,4 @@ -import { Factory, PrimeSdk } from '../src'; +import { EtherspotBundler, Factory, PrimeSdk } from '../src'; import * as dotenv from 'dotenv'; dotenv.config(); @@ -6,7 +6,9 @@ dotenv.config(); async function main() { // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', factoryWallet: Factory.SIMPLE_ACCOUNT }) + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', factoryWallet: Factory.SIMPLE_ACCOUNT, + bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) + }) // get SimpleAccount address... const address: string = await primeSdk.getCounterFactualAddress(); diff --git a/examples/16-paymaster-arka.ts b/examples/16-paymaster-arka.ts index 7854f387..e1c3defe 100644 --- a/examples/16-paymaster-arka.ts +++ b/examples/16-paymaster-arka.ts @@ -1,5 +1,5 @@ import { ethers, utils } from 'ethers'; -import { PrimeSdk } from '../src'; +import { EtherspotBundler, PrimeSdk } from '../src'; import { printOp } from '../src/sdk/common/OperationUtils'; import * as dotenv from 'dotenv'; import { sleep } from '../src/sdk/common'; @@ -18,6 +18,7 @@ async function main() { // initializing sdk... const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', + bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/19-paymaster-validUntil-validAfter.ts b/examples/19-paymaster-validUntil-validAfter.ts index 6606f64f..f9efd519 100644 --- a/examples/19-paymaster-validUntil-validAfter.ts +++ b/examples/19-paymaster-validUntil-validAfter.ts @@ -1,5 +1,5 @@ import { ethers } from 'ethers'; -import { PrimeSdk } from '../src'; +import { EtherspotBundler, PrimeSdk } from '../src'; import { printOp } from '../src/sdk/common/OperationUtils'; import * as dotenv from 'dotenv'; import { sleep } from '../src/sdk/common'; @@ -16,7 +16,7 @@ const queryString = `?apiKey=${arka_api_key}&chainId=${Number(process.env.CHAIN_ async function main() { // initializing sdk... const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { - chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', + chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/20-callGasLimit.ts b/examples/20-callGasLimit.ts index 6eca5432..d3aab83b 100644 --- a/examples/20-callGasLimit.ts +++ b/examples/20-callGasLimit.ts @@ -1,5 +1,5 @@ import { ethers } from 'ethers'; -import { PrimeSdk } from '../src'; +import { EtherspotBundler, PrimeSdk } from '../src'; import { printOp } from '../src/sdk/common/OperationUtils'; import * as dotenv from 'dotenv'; import { sleep } from '../src/sdk/common'; @@ -11,7 +11,9 @@ const value = '0.0001'; // transfer value async function main() { // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' }) + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', + bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) + }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/21-get-multiple-accounts.ts b/examples/21-get-multiple-accounts.ts index 57696c84..9fed1c2d 100644 --- a/examples/21-get-multiple-accounts.ts +++ b/examples/21-get-multiple-accounts.ts @@ -1,4 +1,4 @@ -import { PrimeSdk } from '../src'; +import { EtherspotBundler, PrimeSdk } from '../src'; import * as dotenv from 'dotenv'; dotenv.config(); @@ -7,7 +7,7 @@ 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' }, + { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) }, ); // get EtherspotWallet address for index 0... @@ -17,7 +17,7 @@ async function main() { // 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 }, + { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', index: 1, bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) }, ); // get EtherspotWallet address for index 1... diff --git a/examples/22-concurrent-userops.ts b/examples/22-concurrent-userops.ts index 779a94bd..2843a3ca 100644 --- a/examples/22-concurrent-userops.ts +++ b/examples/22-concurrent-userops.ts @@ -1,5 +1,5 @@ import { ethers, providers } from 'ethers'; -import { PrimeSdk } from '../src'; +import { EtherspotBundler, PrimeSdk } from '../src'; import { printOp } from '../src/sdk/common/OperationUtils'; import * as dotenv from 'dotenv'; import { sleep } from '../src/sdk/common'; @@ -12,7 +12,9 @@ const value = '0.000001'; // transfer value async function main() { const provider = new providers.JsonRpcProvider(process.env.RPC_PROVIDER_URL); // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key' }) + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', + bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) + }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/23-bundlerApiKey.ts b/examples/23-bundlerApiKey.ts index 7a88880d..7b621f80 100644 --- a/examples/23-bundlerApiKey.ts +++ b/examples/23-bundlerApiKey.ts @@ -1,12 +1,15 @@ -import { PrimeSdk } from '../src'; +import { EtherspotBundler, PrimeSdk } from '../src'; import * as dotenv from 'dotenv'; dotenv.config(); async function main() { + const etherspotBundlerApiKey = ''; // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', etherspotBundlerApiKey: '' }) + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', + bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), etherspotBundlerApiKey) + }) // get EtherspotWallet address... const address: string = await primeSdk.getCounterFactualAddress(); diff --git a/src/sdk/base/BaseAccountAPI.ts b/src/sdk/base/BaseAccountAPI.ts index be0757a2..a5dfcf95 100644 --- a/src/sdk/base/BaseAccountAPI.ts +++ b/src/sdk/base/BaseAccountAPI.ts @@ -70,21 +70,19 @@ export abstract class BaseAccountAPI { throw new Exception('Invalid wallet provider'); } - // const env = Env.prepare(optionsLike.env); - const { chainId, // stateStorage, rpcProviderUrl, - bundlerRpcUrl, factoryWallet, + bundlerProvider, } = optionsLike; this.services = { networkService: new NetworkService(chainId), walletService: new WalletService(params.walletProvider, { provider: rpcProviderUrl, - }, bundlerRpcUrl, chainId), + }, bundlerProvider.url, chainId), stateService: new StateService({ storage: stateStorage, }), diff --git a/src/sdk/bundler/index.ts b/src/sdk/bundler/index.ts new file mode 100644 index 00000000..e7adc5a7 --- /dev/null +++ b/src/sdk/bundler/index.ts @@ -0,0 +1,2 @@ +export * from './interface'; +export * from './providers'; \ No newline at end of file diff --git a/src/sdk/bundler/interface.ts b/src/sdk/bundler/interface.ts new file mode 100644 index 00000000..10de729c --- /dev/null +++ b/src/sdk/bundler/interface.ts @@ -0,0 +1,6 @@ + +export interface BundlerProvider { + readonly url: string; +} + +export type BundlerProviderLike = BundlerProvider; \ No newline at end of file diff --git a/src/sdk/bundler/providers/EtherspotBundler.ts b/src/sdk/bundler/providers/EtherspotBundler.ts new file mode 100644 index 00000000..e750cfb8 --- /dev/null +++ b/src/sdk/bundler/providers/EtherspotBundler.ts @@ -0,0 +1,18 @@ +import { getNetworkConfig } from "../../network/constants"; +import { BundlerProvider } from "../interface"; + +export class EtherspotBundler implements BundlerProvider { + readonly url: string; + readonly apiKey: string; + readonly chainId: string; + + constructor(chainId: number, apiKey?: string, bundlerUrl?: string) { + if (!bundlerUrl) { + const networkConfig = getNetworkConfig(chainId); + bundlerUrl = networkConfig.bundler; + } + if (apiKey) this.url = bundlerUrl + '?api-key=' + apiKey; + else this.url = bundlerUrl; + this.apiKey = apiKey; + } +} \ No newline at end of file diff --git a/src/sdk/bundler/providers/GenericBundler.ts b/src/sdk/bundler/providers/GenericBundler.ts new file mode 100644 index 00000000..2446ad75 --- /dev/null +++ b/src/sdk/bundler/providers/GenericBundler.ts @@ -0,0 +1,9 @@ +import { BundlerProvider } from "../interface"; + + +export class GenericBundler implements BundlerProvider { + readonly url: string; + constructor(bundlerUrl: string) { + this.url = bundlerUrl; + } +} \ No newline at end of file diff --git a/src/sdk/bundler/providers/index.ts b/src/sdk/bundler/providers/index.ts new file mode 100644 index 00000000..4b6685cc --- /dev/null +++ b/src/sdk/bundler/providers/index.ts @@ -0,0 +1,2 @@ +export * from './GenericBundler'; +export * from './EtherspotBundler'; \ No newline at end of file diff --git a/src/sdk/index.ts b/src/sdk/index.ts index 9967fe6e..16f02391 100644 --- a/src/sdk/index.ts +++ b/src/sdk/index.ts @@ -8,6 +8,7 @@ export * from './interfaces'; export * from './network'; export * from './state'; export * from './wallet'; +export * from './bundler'; export { PrimeSdk, DataUtils }; export default PrimeSdk; \ No newline at end of file diff --git a/src/sdk/interfaces.ts b/src/sdk/interfaces.ts index 663627a4..6b4e4bf0 100644 --- a/src/sdk/interfaces.ts +++ b/src/sdk/interfaces.ts @@ -1,3 +1,4 @@ +import { BundlerProviderLike } from './bundler'; import { StateStorage } from './state'; export interface PaymasterApi { @@ -14,8 +15,8 @@ export enum Factory { export interface SdkOptions { chainId: number; projectKey: string; + bundlerProvider: BundlerProviderLike; stateStorage?: StateStorage; - bundlerRpcUrl?: string; rpcProviderUrl?: string; graphqlEndpoint?: string; etherspotBundlerApiKey?: string; diff --git a/src/sdk/network/constants.ts b/src/sdk/network/constants.ts index d7f042b2..cd6f6e42 100644 --- a/src/sdk/network/constants.ts +++ b/src/sdk/network/constants.ts @@ -147,7 +147,7 @@ export const Networks: { }, [10]: { chainId: 10, - bundler: 'https://rpc.etherspot.io/optimism?api-key=', + bundler: 'https://rpc.etherspot.io/optimism', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -160,7 +160,7 @@ export const Networks: { }, [137]: { chainId: 137, - bundler: 'https://rpc.etherspot.io/polygon?api-key=', + bundler: 'https://rpc.etherspot.io/polygon', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -173,7 +173,7 @@ export const Networks: { }, [42161]: { chainId: 42161, - bundler: 'https://rpc.etherspot.io/arbitrum?api-key=', + bundler: 'https://rpc.etherspot.io/arbitrum', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -199,7 +199,7 @@ export const Networks: { }, [1]: { chainId: 1, - bundler: 'https://rpc.etherspot.io/ethereum?api-key=', + bundler: 'https://rpc.etherspot.io/ethereum', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -238,7 +238,7 @@ export const Networks: { }, [122]: { chainId: 122, - bundler: 'https://rpc.etherspot.io/fuse?api-key=', + bundler: 'https://rpc.etherspot.io/fuse', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -264,7 +264,7 @@ export const Networks: { }, [100]: { chainId: 100, - bundler: 'https://rpc.etherspot.io/gnosis?api-key=', + bundler: 'https://rpc.etherspot.io/gnosis', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -329,7 +329,7 @@ export const Networks: { }, [5000]: { chainId: 5000, - bundler: 'https://rpc.etherspot.io/mantle?api-key=', + bundler: 'https://rpc.etherspot.io/mantle', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -355,7 +355,7 @@ export const Networks: { }, [43114]: { chainId: 43114, - bundler: 'https://rpc.etherspot.io/avalanche?api-key=', + bundler: 'https://rpc.etherspot.io/avalanche', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -368,7 +368,7 @@ export const Networks: { }, [8453]: { chainId: 8453, - bundler: 'https://rpc.etherspot.io/base?api-key=', + bundler: 'https://rpc.etherspot.io/base', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -381,7 +381,7 @@ export const Networks: { }, [56]: { chainId: 56, - bundler: 'https://rpc.etherspot.io/bnb?api-key=', + bundler: 'https://rpc.etherspot.io/bnb', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -420,7 +420,7 @@ export const Networks: { }, [59144]: { chainId: 59144, - bundler: 'https://rpc.etherspot.io/linea?api-key=', + bundler: 'https://rpc.etherspot.io/linea', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -459,7 +459,7 @@ export const Networks: { }, [14]: { chainId: 14, - bundler: 'https://rpc.etherspot.io/flare?api-key=', + bundler: 'https://rpc.etherspot.io/flare', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { @@ -485,7 +485,7 @@ export const Networks: { }, [534352]: { chainId: 534352, - bundler: 'https://rpc.etherspot.io/scroll?api-key=', + bundler: 'https://rpc.etherspot.io/scroll', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { diff --git a/src/sdk/sdk.ts b/src/sdk/sdk.ts index 1fc9faf6..800c5c2d 100644 --- a/src/sdk/sdk.ts +++ b/src/sdk/sdk.ts @@ -49,18 +49,13 @@ export class PrimeSdk { chainId, rpcProviderUrl, accountAddress, - etherspotBundlerApiKey, + bundlerProvider, } = optionsLike; this.chainId = chainId; this.index = index ?? 0; const networkConfig = getNetworkConfig(chainId); - if (!optionsLike.bundlerRpcUrl) { - if (!networkConfig || networkConfig.bundler == '') throw new Exception('No bundler Rpc provided'); - optionsLike.bundlerRpcUrl = `${networkConfig.bundler.includes("?api-key=") ? networkConfig.bundler + etherspotBundlerApiKey : networkConfig.bundler}`; - } - if (networkConfig) { optionsLike.graphqlEndpoint = networkConfig.graphqlEndpoint; } @@ -71,7 +66,7 @@ export class PrimeSdk { if (rpcProviderUrl) { provider = new providers.JsonRpcProvider(rpcProviderUrl); - } else provider = new providers.JsonRpcProvider(optionsLike.bundlerRpcUrl); + } else provider = new providers.JsonRpcProvider(bundlerProvider.url); let entryPointAddress = '', walletFactoryAddress = ''; if (Networks[chainId]) { @@ -116,7 +111,7 @@ export class PrimeSdk { index: this.index, }) } - this.bundler = new HttpRpcClient(optionsLike.bundlerRpcUrl, entryPointAddress, chainId); + this.bundler = new HttpRpcClient(bundlerProvider.url, entryPointAddress, chainId); } From c43251ee0c803119d4419bc15c0dc2b4f988c612 Mon Sep 17 00:00:00 2001 From: Vignesh Date: Thu, 1 Feb 2024 15:33:56 +0530 Subject: [PATCH 4/7] added default bundler provider --- src/sdk/bundler/providers/EtherspotBundler.ts | 7 ++++++- src/sdk/interfaces.ts | 2 +- src/sdk/sdk.ts | 10 +++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/sdk/bundler/providers/EtherspotBundler.ts b/src/sdk/bundler/providers/EtherspotBundler.ts index e750cfb8..36e345da 100644 --- a/src/sdk/bundler/providers/EtherspotBundler.ts +++ b/src/sdk/bundler/providers/EtherspotBundler.ts @@ -1,3 +1,4 @@ +import { Exception } from "../../common"; import { getNetworkConfig } from "../../network/constants"; import { BundlerProvider } from "../interface"; @@ -9,9 +10,13 @@ export class EtherspotBundler implements BundlerProvider { constructor(chainId: number, apiKey?: string, bundlerUrl?: string) { if (!bundlerUrl) { const networkConfig = getNetworkConfig(chainId); + if (!networkConfig || networkConfig.bundler == '') throw new Exception('No bundler url provided') bundlerUrl = networkConfig.bundler; } - if (apiKey) this.url = bundlerUrl + '?api-key=' + apiKey; + if (apiKey) { + if (bundlerUrl.includes('?api-key=')) this.url = bundlerUrl + apiKey; + else this.url = bundlerUrl + '?api-key=' + apiKey; + } else this.url = bundlerUrl; this.apiKey = apiKey; } diff --git a/src/sdk/interfaces.ts b/src/sdk/interfaces.ts index 6b4e4bf0..4ef7301f 100644 --- a/src/sdk/interfaces.ts +++ b/src/sdk/interfaces.ts @@ -15,7 +15,7 @@ export enum Factory { export interface SdkOptions { chainId: number; projectKey: string; - bundlerProvider: BundlerProviderLike; + bundlerProvider?: BundlerProviderLike; stateStorage?: StateStorage; rpcProviderUrl?: string; graphqlEndpoint?: string; diff --git a/src/sdk/sdk.ts b/src/sdk/sdk.ts index 800c5c2d..dc46acbe 100644 --- a/src/sdk/sdk.ts +++ b/src/sdk/sdk.ts @@ -19,6 +19,7 @@ import { OnRamperDto, SignMessageDto, validateDto } from './dto'; import { ZeroDevWalletAPI } from './base/ZeroDevWalletAPI'; import { SimpleAccountAPI } from './base/SimpleAccountWalletAPI'; import { ErrorHandler } from './errorHandler/errorHandler.service'; +import { EtherspotBundler } from './bundler'; /** * Prime-Sdk @@ -49,13 +50,16 @@ export class PrimeSdk { chainId, rpcProviderUrl, accountAddress, - bundlerProvider, } = optionsLike; this.chainId = chainId; this.index = index ?? 0; const networkConfig = getNetworkConfig(chainId); + if (!optionsLike.bundlerProvider) { + optionsLike.bundlerProvider = new EtherspotBundler(chainId); + } + if (networkConfig) { optionsLike.graphqlEndpoint = networkConfig.graphqlEndpoint; } @@ -66,7 +70,7 @@ export class PrimeSdk { if (rpcProviderUrl) { provider = new providers.JsonRpcProvider(rpcProviderUrl); - } else provider = new providers.JsonRpcProvider(bundlerProvider.url); + } else provider = new providers.JsonRpcProvider(optionsLike.bundlerProvider.url); let entryPointAddress = '', walletFactoryAddress = ''; if (Networks[chainId]) { @@ -111,7 +115,7 @@ export class PrimeSdk { index: this.index, }) } - this.bundler = new HttpRpcClient(bundlerProvider.url, entryPointAddress, chainId); + this.bundler = new HttpRpcClient(optionsLike.bundlerProvider.url, entryPointAddress, chainId); } From ab5152dec714121e9873b77cd831e3b999c62e0a Mon Sep 17 00:00:00 2001 From: Vignesh Date: Mon, 12 Feb 2024 15:02:19 +0530 Subject: [PATCH 5/7] Added bundler api key and fuse sparknet bundlerUrl --- examples/01-get-address.ts | 4 +++- examples/02-transfer-funds.ts | 3 ++- examples/03-transfer-erc20.ts | 3 ++- examples/04-transfer-nft.ts | 3 ++- examples/12-add-guardians.ts | 4 +++- examples/13-paymaster.ts | 3 ++- examples/14-zeroDev-address.ts | 3 ++- examples/15-simpleAccount-address.ts | 3 ++- examples/16-paymaster-arka.ts | 3 ++- examples/19-paymaster-validUntil-validAfter.ts | 3 ++- examples/20-callGasLimit.ts | 3 ++- examples/21-get-multiple-accounts.ts | 6 ++++-- examples/22-concurrent-userops.ts | 3 ++- examples/23-bundlerApiKey.ts | 2 +- src/sdk/network/constants.ts | 2 +- 15 files changed, 32 insertions(+), 16 deletions(-) diff --git a/examples/01-get-address.ts b/examples/01-get-address.ts index a9610b09..2785a1a7 100644 --- a/examples/01-get-address.ts +++ b/examples/01-get-address.ts @@ -5,8 +5,10 @@ dotenv.config(); async function main() { + const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9'; + const customBundlerUrl = ''; // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), '') }) // Testnets dont need apiKey on bundlerProvider + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey, customBundlerUrl) }) // Testnets dont need apiKey on bundlerProvider // get EtherspotWallet address... const address: string = await primeSdk.getCounterFactualAddress(); diff --git a/examples/02-transfer-funds.ts b/examples/02-transfer-funds.ts index 3dece46c..845dcee3 100644 --- a/examples/02-transfer-funds.ts +++ b/examples/02-transfer-funds.ts @@ -8,10 +8,11 @@ dotenv.config(); const recipient = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address const value = '0.00001'; // transfer value +const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9'; async function main() { // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) }) + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/03-transfer-erc20.ts b/examples/03-transfer-erc20.ts index f2720d61..ad661ded 100644 --- a/examples/03-transfer-erc20.ts +++ b/examples/03-transfer-erc20.ts @@ -11,10 +11,11 @@ dotenv.config(); const recipient = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address const value = '0.1'; // transfer value const tokenAddress = '0x326C977E6efc84E512bB9C30f76E30c160eD06FB'; +const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9'; async function main() { // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) }) + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/04-transfer-nft.ts b/examples/04-transfer-nft.ts index 902e1211..b53a320b 100644 --- a/examples/04-transfer-nft.ts +++ b/examples/04-transfer-nft.ts @@ -10,10 +10,11 @@ dotenv.config(); const recipient = '0xD129dB5e418e389c3F7D3ae0B8771B3f76799A52'; // recipient wallet address const tokenAddress = '0xe55C5793a52AF819fBf3e87a23B36708E6FDd2Cc'; const tokenId = 4; +const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9'; async function main() { // initializating sdk... - const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) }) + const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/12-add-guardians.ts b/examples/12-add-guardians.ts index 24e7cd9d..08f94846 100644 --- a/examples/12-add-guardians.ts +++ b/examples/12-add-guardians.ts @@ -7,10 +7,12 @@ import { sleep } from '../src/sdk/common'; dotenv.config(); async function main() { + const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9'; + // initializating sdk... const primeSdk = new PrimeSdk( { privateKey: process.env.WALLET_PRIVATE_KEY }, - { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) }, + { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }, ); console.log('address: ', primeSdk.state.EOAAddress); diff --git a/examples/13-paymaster.ts b/examples/13-paymaster.ts index 012d0796..ac01217d 100644 --- a/examples/13-paymaster.ts +++ b/examples/13-paymaster.ts @@ -9,12 +9,13 @@ dotenv.config(); const recipient = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address const value = '0.01'; // transfer value const api_key = 'arka_public_key'; // Only testnets are available, if you need further assistance in setting up a paymaster service for your dapp, please reach out to us on discord or https://etherspot.fyi/arka/intro +const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9'; async function main() { // initializating sdk... const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', - bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) + bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/14-zeroDev-address.ts b/examples/14-zeroDev-address.ts index 03006bf6..facd2890 100644 --- a/examples/14-zeroDev-address.ts +++ b/examples/14-zeroDev-address.ts @@ -5,9 +5,10 @@ dotenv.config(); async function main() { + const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9'; // initializating sdk... const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', factoryWallet: Factory.ZERO_DEV, - bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) + bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) // get ZeroDev address... diff --git a/examples/15-simpleAccount-address.ts b/examples/15-simpleAccount-address.ts index 7a95a8cc..dbf83e1c 100644 --- a/examples/15-simpleAccount-address.ts +++ b/examples/15-simpleAccount-address.ts @@ -5,9 +5,10 @@ dotenv.config(); async function main() { + const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9'; // initializating sdk... const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', factoryWallet: Factory.SIMPLE_ACCOUNT, - bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) + bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) // get SimpleAccount address... diff --git a/examples/16-paymaster-arka.ts b/examples/16-paymaster-arka.ts index e1c3defe..bf18e170 100644 --- a/examples/16-paymaster-arka.ts +++ b/examples/16-paymaster-arka.ts @@ -9,6 +9,7 @@ dotenv.config(); const recipient = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address const value = '0.0001'; // transfer value +const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9'; const arka_api_key = 'arka_public_key'; const arka_url = 'https://arka.etherspot.io'; // Only testnets are available, if you need further assistance in setting up a paymaster service for your dapp, please reach out to us on discord or https://etherspot.fyi/arka/intro @@ -18,7 +19,7 @@ async function main() { // initializing sdk... const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', - bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) + bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/19-paymaster-validUntil-validAfter.ts b/examples/19-paymaster-validUntil-validAfter.ts index f9efd519..91ec382b 100644 --- a/examples/19-paymaster-validUntil-validAfter.ts +++ b/examples/19-paymaster-validUntil-validAfter.ts @@ -8,6 +8,7 @@ dotenv.config(); const recipient = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address const value = '0.0001'; // transfer value +const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9'; const arka_api_key = 'arka_public_key'; // Only testnets are available, if you need further assistance in setting up a paymaster service for your dapp, please reach out to us on discord or https://etherspot.fyi/arka/intro const arka_url = 'https://arka.etherspot.io'; @@ -16,7 +17,7 @@ const queryString = `?apiKey=${arka_api_key}&chainId=${Number(process.env.CHAIN_ async function main() { // initializing sdk... const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { - chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) + chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/20-callGasLimit.ts b/examples/20-callGasLimit.ts index d3aab83b..fb749804 100644 --- a/examples/20-callGasLimit.ts +++ b/examples/20-callGasLimit.ts @@ -8,11 +8,12 @@ dotenv.config(); const recipient = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address const value = '0.0001'; // transfer value +const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9'; async function main() { // initializating sdk... const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', - bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) + bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/21-get-multiple-accounts.ts b/examples/21-get-multiple-accounts.ts index 9fed1c2d..98ff06e9 100644 --- a/examples/21-get-multiple-accounts.ts +++ b/examples/21-get-multiple-accounts.ts @@ -3,11 +3,13 @@ import * as dotenv from 'dotenv'; dotenv.config(); +const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9'; + 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', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) }, + { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }, ); // get EtherspotWallet address for index 0... @@ -17,7 +19,7 @@ async function main() { // 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, bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) }, + { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', index: 1, bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }, ); // get EtherspotWallet address for index 1... diff --git a/examples/22-concurrent-userops.ts b/examples/22-concurrent-userops.ts index 2843a3ca..5547fe5b 100644 --- a/examples/22-concurrent-userops.ts +++ b/examples/22-concurrent-userops.ts @@ -8,12 +8,13 @@ dotenv.config(); const recipient = '0x80a1874E1046B1cc5deFdf4D3153838B72fF94Ac'; // recipient wallet address const value = '0.000001'; // transfer value +const bundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9'; async function main() { const provider = new providers.JsonRpcProvider(process.env.RPC_PROVIDER_URL); // initializating sdk... const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', - bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID)) + bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), bundlerApiKey) }) console.log('address: ', primeSdk.state.EOAAddress) diff --git a/examples/23-bundlerApiKey.ts b/examples/23-bundlerApiKey.ts index 7b621f80..bb845ebe 100644 --- a/examples/23-bundlerApiKey.ts +++ b/examples/23-bundlerApiKey.ts @@ -5,7 +5,7 @@ dotenv.config(); async function main() { - const etherspotBundlerApiKey = ''; + const etherspotBundlerApiKey = 'eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9'; // initializating sdk... const primeSdk = new PrimeSdk({ privateKey: process.env.WALLET_PRIVATE_KEY }, { chainId: Number(process.env.CHAIN_ID), projectKey: 'public-prime-testnet-key', bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID), etherspotBundlerApiKey) diff --git a/src/sdk/network/constants.ts b/src/sdk/network/constants.ts index cd6f6e42..82de3bbe 100644 --- a/src/sdk/network/constants.ts +++ b/src/sdk/network/constants.ts @@ -251,7 +251,7 @@ export const Networks: { }, [123]: { chainId: 123, - bundler: '', + bundler: 'https://fusetestnet-bundler.etherspot.io/', contracts: { entryPoint: '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789', walletFactory: { From e0ee5e5c050b6380ecb12f17a7bf9899a87878bb Mon Sep 17 00:00:00 2001 From: Vignesh Date: Mon, 12 Feb 2024 15:08:15 +0530 Subject: [PATCH 6/7] changed version and changelog --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ce561f4..f5eed278 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ # Changelog -## [1.4.3] - 2024-01-30 +## [1.5.2] - 2024-02-12 ### New - Added `GenericBundler` and `EtherspotBundler` as bundlerProviders and removed bundlerUrl params from SdkOptions diff --git a/package.json b/package.json index cafc63bc..995ba200 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@etherspot/prime-sdk", - "version": "1.5.1", + "version": "1.5.2", "description": "Etherspot Prime (Account Abstraction) SDK", "keywords": [ "ether", From abd5cea57f2eb728b1de5c8bb5ea0be7039ad32c Mon Sep 17 00:00:00 2001 From: Vignesh Date: Tue, 13 Feb 2024 00:13:39 +0530 Subject: [PATCH 7/7] added to readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9b262cd1..bc3646de 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,8 @@ npm i @etherspot/prime-sdk Or follow our introductory guide on our docs [here](https://etherspot.fyi/getting-started) which walk you through cloning down an example repo and setting up a dapp in your own environment. +The mainnet bundler API key `eyJvcmciOiI2NTIzZjY5MzUwOTBmNzAwMDFiYjJkZWIiLCJpZCI6IjMxMDZiOGY2NTRhZTRhZTM4MGVjYjJiN2Q2NDMzMjM4IiwiaCI6Im11cm11cjEyOCJ9` is included in the example programs which is a public API key with rate limits, to get higher limits register to https://portal.etherspot.io + ## 📖 Documentation - [Quick Start](https://etherspot.fyi/getting-started)