Skip to content

Commit

Permalink
Merge pull request #67 from bcnmy/Modular_SDK_Update
Browse files Browse the repository at this point in the history
update static create methods for modules
  • Loading branch information
Rahat-ch authored Sep 20, 2023
2 parents 09745ca + 9bd1ee8 commit dd0552a
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 173 deletions.
18 changes: 7 additions & 11 deletions docs/Biconomy AA Stack/Account/initialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,24 @@ import { BiconomySmartAccountV2, DEFAULT_ENTRYPOINT_ADDRESS } from "@biconomy/a

Update your import from the account package to also include `BiconomySmartAccountV2` and also import Wallet, providers, and ethers from the ethers package.

Now we need an object that will hold the configuration values for our Smart Account.
Lets create a new instance of the account using the create method on the BiconomySmartAccount class. See a detailed explanation of each argument supplied below. We then await the initialisation of the account and log out two values to out terminal: the owner of the account and the smart account address. The owner should be your signer and the smart account address will be a new address referring to the address of this wallet.

```typescript
const biconomySmartAccountConfig = {
let biconomySmartAccount = await BiconomySmartAccountV2.create({
signer: {}, //ethers signer object
chainId: ChainId.POLYGON_MUMBAI, //or any chain of your choice
bundler: bundler, // instance of bundler
paymaster: paymaster, // instance of paymaster
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS, //entry point address for chain
defaultValidationModule: ownerShipModule, // either ECDSA or Multi chain to start
activeValidationModule: ownerShipModule // either ECDSA or Multi chain to start
}
})
const address = await biconomySmartAccount.getSmartAccountAddress()
console.log("address", address)
```

Account Create method takes the following:

| Key | Description |
| ------------- | ------------- |
| signer | This signer will be used for signing userOps for any transactions you build. You can supply your EOA wallet as a signer|
Expand All @@ -72,11 +76,3 @@ const biconomySmartAccountConfig = {
| defaultValidationModule | Validation module to initialize with this should be either ECDSA or Multi chain |
| activeValidationModule | Validation module to initialize with this should be either ECDSA or Multi chain and this can be changed later once you activate further modules |

Lets create a new instance of the account using the BiconomySmartAccount class and passing it the biconomySmartAccountConfig configuration, we created above. We then await the initialisation of the account and log out two values to out terminal: the owner of the account and the smart account address. The owner should be your signer and the smart account address will be a new address referring to the address of this wallet.

```typescript
let biconomySmartAccount = new BiconomySmartAccountV2(biconomySmartAccountConfig)
biconomySmartAccount = await biconomySmartAccount.init()
const address = await biconomySmartAccount.getSmartAccountAddress()
console.log("address", address)
``
9 changes: 3 additions & 6 deletions docs/Biconomy AA Stack/Account/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,20 @@ import { IPaymaster, BiconomyPaymaster } from '@biconomy/paymaster'
})

// instance of ownership module - this can alternatively be the multi chain module
const ownerShipModule = new ECDSAOwnershipValidationModule({
const ownerShipModule = await ECDSAOwnershipValidationModule.create({
signer: {}, // ethers signer object
moduleAddress: DEFAULT_ECDSA_OWNERSHIP_MODULE
})

const biconomySmartAccountConfig = {
const biconomyAccount = await BiconomySmartAccountV2.create({
signer: {}, //ethers signer object
chainId: ChainId.POLYGON_MUMBAI, //or any chain of your choice
bundler: bundler, // instance of bundler
paymaster: paymaster, // instance of paymaster
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS, //entry point address for chain
defaultValidationModule: ownerShipModule, // either ECDSA or Multi chain to start
activeValidationModule: ownerShipModule // either ECDSA or Multi chain to start
}

const biconomyAccount = new BiconomySmartAccountV2(biconomySmartAccountConfig)
const biconomySmartAccount = await biconomyAccount.init()
})
const address = await biconomySmartAccount.getSmartAccountAddress()

```
Expand Down
4 changes: 2 additions & 2 deletions docs/Biconomy AA Stack/Modules/initialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sidebar_position: 3
// This is how you create ECDSA module instance in your dapp's
import { ECDSAOwnershipValidationModule, DEFAULT_ECDSA_OWNERSHIP_MODULE } from "@biconomy/modules";

const module = new ECDSAOwnershipValidationModule({
const module = await ECDSAOwnershipValidationModule.create({
signer: signer, // you will need to supply a signer from an EOA in this step
moduleAddress: DEFAULT_ECDSA_OWNERSHIP_MODULE
})
Expand All @@ -21,7 +21,7 @@ import { ECDSAOwnershipValidationModule, DEFAULT_ECDSA_OWNERSHIP_MODULE } from "
// This is how you create ECDSA module instance in your dapp's
import { MultiChainValidationModule, DEFAULT_MULTICHAIN_MODULE } from "@biconomy/modules";

const multiChainModule = new MultiChainValidationModule({
const multiChainModule = await MultiChainValidationModule.create({
signer: signer,
moduleAddress: DEFAULT_MULTICHAIN_MODULE
})
Expand Down
33 changes: 20 additions & 13 deletions docs/addons/Social Login/web3auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ Next, you will need to connect the provider to the Biconomy Smart Account packag
yarn add @biconomy/account
yarn add @biconomy/bundler
yarn add @biconomy/paymaster
yarn add @biconomy/modules
// or
npm install @biconomy/account
npm install @biconomy/bundler
npm install @biconomy/paymaster
npm install @biconomy/modules
```
:::info
Expand All @@ -106,11 +108,12 @@ If you have problems with using the Dashboard and configuring your dApp and Gas
```js
import { IBundler, Bundler } from '@biconomy/bundler'
import { BiconomySmartAccount, BiconomySmartAccountConfig, DEFAULT_ENTRYPOINT_ADDRESS } from "@biconomy/account"
import { BiconomySmartAccountV2, DEFAULT_ENTRYPOINT_ADDRESS } from "@biconomy/account"
import {
IPaymaster,
BiconomyPaymaster,
} from '@biconomy/paymaster'
import { ECDSAOwnershipValidationModule, DEFAULT_ECDSA_OWNERSHIP_MODULE } from "@biconomy/modules";

const bundler: IBundler = new Bundler({
bundlerUrl: 'https://bundler.biconomy.io/api/v2/80001/nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44', // you can get this value from biconomy dashboard.
Expand All @@ -122,18 +125,22 @@ const paymaster: IPaymaster = new BiconomyPaymaster({
paymasterUrl: 'https://paymaster.biconomy.io/api/v1/80001/Tpk8nuCUd.70bd3a7f-a368-4e5a-af14-80c7f1fcda1a'
})

const biconomySmartAccountConfig: BiconomySmartAccountConfig = {
signer: web3Provider.getSigner(),
chainId: ChainId.POLYGON_MUMBAI,
bundler: bundler,
paymaster: paymaster
}
let biconomySmartAccount = new BiconomySmartAccount(biconomySmartAccountConfig)
biconomySmartAccount = await biconomySmartAccount.init()

// this provider is from the social login which we created in previous setup
let smartAccount = new SmartAccount(provider, options);
smartAccount = await smartAccount.init();
const module = await ECDSAOwnershipValidationModule.create({
signer: wallet,
moduleAddress: DEFAULT_ECDSA_OWNERSHIP_MODULE
})


let biconomySmartAccount = await BiconomySmartAccountV2.create({
signer: wallet,
chainId: ChainId.POLYGON_MUMBAI,
bundler: bundler,
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
defaultValidationModule: module,
activeValidationModule: module
})


```
:::info
Expand Down
38 changes: 14 additions & 24 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,32 +123,25 @@ Now initialize it:

```typescript

const module = new ECDSAOwnershipValidationModule({
const module = await ECDSAOwnershipValidationModule.create({
signer: wallet,
moduleAddress: DEFAULT_ECDSA_OWNERSHIP_MODULE
})

```

We now need an object that will hold the configuration values for our Smart Account.
Now with the config setup let's create a smart account:

```typescript
const biconomySmartAccountConfig = {
async function createAccount() {
let biconomySmartAccount = await BiconomySmartAccountV2.create({
signer: wallet,
chainId: ChainId.POLYGON_MUMBAI,
bundler: bundler,
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
defaultValidationModule: module,
activeValidationModule: module
}
```

Now with the config setup let's create a smart account:

```typescript
async function createAccount() {
let biconomySmartAccount = new BiconomySmartAccount(biconomySmartAccountConfig)
biconomySmartAccount = await biconomySmartAccount.init()
})
console.log("owner: ", biconomySmartAccount.owner)
console.log("address: ", await biconomySmartAccount.getSmartAccountAddress())
return biconomySmartAccount;
Expand Down Expand Up @@ -231,23 +224,20 @@ const bundler: IBundler = new Bundler({
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
})

const module = new ECDSAOwnershipValidationModule({
const module = await ECDSAOwnershipValidationModule.create({
signer: wallet,
moduleAddress: DEFAULT_ECDSA_OWNERSHIP_MODULE
})

const biconomySmartAccountConfig = {
signer: wallet,
chainId: ChainId.POLYGON_MUMBAI,
bundler: bundler,
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
defaultValidationModule: module,
activeValidationModule: module
};

async function createAccount() {
let biconomyAccount = new BiconomySmartAccountV2(biconomySmartAccountConfig)
biconomyAccount = await biconomyAccount.init()
let biconomyAccount = await BiconomySmartAccountV2.create({
signer: wallet,
chainId: ChainId.POLYGON_MUMBAI,
bundler: bundler,
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
defaultValidationModule: module,
activeValidationModule: module
})
console.log("address", biconomyAccount.accountAddress)
return biconomyAccount
}
Expand Down
1 change: 0 additions & 1 deletion docs/tutorials/React_vite/initialize.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ yarn add
@biconomy/core-types
@biconomy/paymaster
@biconomy/web3-auth
@biconomy/node-client -S
```

We will use these tools to build out our front end. In addition, lets also
Expand Down
21 changes: 5 additions & 16 deletions docs/tutorials/React_vite/sdk-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,14 @@ async function setupSmartAccount() {
setProvider(web3Provider);

try {
const biconomySmartAccountConfig = {
let biconomySmartAccount = await BiconomySmartAccountV2.create({
signer: web3Provider.getSigner(),
chainId: ChainId.POLYGON_MUMBAI,
bundler: bundler,
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
defaultValidationModule: module,
activeValidationModule: module
}
let biconomySmartAccount = new BiconomySmartAccountV2(biconomySmartAccountConfig)
biconomySmartAccount = await biconomySmartAccount.init()
})
console.log("owner: ", biconomySmartAccount.owner)
console.log("address: ", await biconomySmartAccount.getSmartAccountAddress())
console.log("deployed: ", await biconomySmartAccount.isAccountDeployed( await biconomySmartAccount.getSmartAccountAddress()))
Expand Down Expand Up @@ -226,9 +224,8 @@ step-by-step explanation of what it does:
**Setting up BiconomySmartAccount:**
6. **`const biconomySmartAccountConfig`: BiconomySmartAccountConfig = { ... }:**
Creates a configuration object for setting up the BiconomySmartAccount. The
configuration includes the following properties:
6. **`BiconomySmartAccountV2.create()`**
Creates an instance of the BiconomySmartAccount. The configuration includes the following properties:
- `signer:` The signer (wallet) associated with the web3Provider.
- `chainId:` The chain ID, which is set to ChainId.POLYGON_MUMBAI. This
Expand All @@ -239,15 +236,7 @@ step-by-step explanation of what it does:
- `paymaster:` The paymaster used for handling payment processing. It is
expected that the paymaster variable is defined elsewhere in the code.
7. **`let biconomySmartAccount` = new
BiconomySmartAccount(biconomySmartAccountConfig):** Creates a new instance of
BiconomySmartAccount using the provided configuration.
8. **`biconomySmartAccount` = await biconomySmartAccount.init():** Initializes
the BiconomySmartAccount instance by calling the init() method. It likely
performs some internal setup and prepares the account for use.
9. Logging `BiconomySmartAccount` information:
7. Logging `BiconomySmartAccount` information:
- **console.log("owner: ", biconomySmartAccount.owner):** Logs the owner of
the BiconomySmartAccount. The owner property might represent the Ethereum
Expand Down
8 changes: 3 additions & 5 deletions docs/tutorials/nextjs/gaslesstransaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,22 +353,20 @@ const connect = async () => {
);
setProvider(web3Provider)

const module = new ECDSAOwnershipValidationModule({
const module = await ECDSAOwnershipValidationModule.create({
signer: web3Provider.getSigner(),
moduleAddress: DEFAULT_ECDSA_OWNERSHIP_MODULE
})

const biconomySmartAccountConfig = {
let biconomySmartAccount = await BiconomySmartAccountV2.create({
signer: web3Provider.getSigner(),
chainId: ChainId.POLYGON_MUMBAI,
bundler: bundler,
paymaster: paymaster,
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
defaultValidationModule: module,
activeValidationModule: module
}
let biconomySmartAccount = new BiconomySmartAccountV2(biconomySmartAccountConfig)
biconomySmartAccount = await biconomySmartAccount.init()
})
setAddress( await biconomySmartAccount.getSmartAccountAddress())
setSmartAccount(biconomySmartAccount)
setLoading(false)
Expand Down
8 changes: 3 additions & 5 deletions docs/tutorials/nextjs/sdkintegration.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,22 +149,20 @@ const connect = async () => {
);
setProvider(web3Provider)

const module = new ECDSAOwnershipValidationModule({
const module = await ECDSAOwnershipValidationModule.create({
signer: web3Provider.getSigner(),
moduleAddress: DEFAULT_ECDSA_OWNERSHIP_MODULE
})

const biconomySmartAccountConfig = {
let biconomySmartAccount = await BiconomySmartAccountV2.create({
signer: web3Provider.getSigner(),
chainId: ChainId.POLYGON_MUMBAI,
bundler: bundler,
paymaster: paymaster,
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
defaultValidationModule: module,
activeValidationModule: module
}
let biconomySmartAccount = new BiconomySmartAccountV2(biconomySmartAccountConfig)
biconomySmartAccount = await biconomySmartAccount.init()
})
setAddress( await biconomySmartAccount.getSmartAccountAddress())
setSmartAccount(biconomySmartAccount)
setLoading(false)
Expand Down
19 changes: 8 additions & 11 deletions docs/tutorials/nodejs/batchingTransactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,25 @@ const paymaster: IPaymaster = new BiconomyPaymaster({
const provider = new providers.JsonRpcProvider("https://rpc.ankr.com/polygon_mumbai")
const wallet = new Wallet(process.env.PRIVATE_KEY || "", provider);

const module = new ECDSAOwnershipValidationModule({
const module = await ECDSAOwnershipValidationModule.create({
signer: wallet,
moduleAddress: DEFAULT_ECDSA_OWNERSHIP_MODULE
})

const biconomySmartAccountConfig = {
let smartAccount: BiconomySmartAccountV2
let address: string

async function createAccount() {
console.log("creating address")
let biconomySmartAccount = await BiconomySmartAccountV2.create({
signer: wallet,
chainId: ChainId.POLYGON_MUMBAI,
bundler: bundler,
paymaster: paymaster,
entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
defaultValidationModule: module,
activeValidationModule: module
}

let smartAccount: BiconomySmartAccountV2
let address: string

async function createAccount() {
console.log("creating address")
let biconomySmartAccount = new BiconomySmartAccountV2(biconomySmartAccountConfig)
biconomySmartAccount = await biconomySmartAccount.init()
})
address = await biconomySmartAccount.getSmartAccountAddress()
smartAccount = biconomySmartAccount;
return biconomySmartAccount;
Expand Down
Loading

0 comments on commit dd0552a

Please sign in to comment.