# @particle-network/aa

> ## Installation[​](https://docs.walletconnect.com/1.0/#getting-started)

Latest version **2.0.2** (published 2024-09-03) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @particle-network/aa
pnpm add @particle-network/aa
yarn add @particle-network/aa
bun add @particle-network/aa
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2024-09-03 |
| First published | 2023-08-10 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 110.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Maintainers | pantaovay, particle-web3 |

## Links

- npm: https://www.npmjs.com/package/@particle-network/aa
- Repository: https://github.com/Particle-Network/aa-sdk
- npm.io page: https://npm.io/package/@particle-network/aa

## Dependencies (1)

- [axios](https://npm.io/package/axios.md) ^1.3.6

## Recent versions

- 2.0.2 (latest) — 2024-09-03
- 2.0.1 — 2024-08-29
- 2.0.0 — 2024-08-22
- 2.0.0-alpha.3 — 2024-08-22
- 2.0.0-alpha.2 — 2024-08-21
- 2.0.0-alpha.1 — 2024-08-21
- 2.0.0-alpha.0 — 2024-08-20
- 1.5.3 — 2024-07-29
- 1.5.2 — 2024-07-29
- 1.5.1 — 2024-06-06
- 1.5.0 — 2024-05-27
- 1.4.0 — 2024-04-18
- 1.3.4 — 2024-04-09
- 1.3.3 — 2023-11-24
- 1.3.2 — 2023-11-24
- … 6 more at https://npm.io/package/@particle-network/aa/versions

## README

# Particle AA SDK

## Installation[​](https://docs.walletconnect.com/1.0/#getting-started) <a href="#getting-started" id="getting-started"></a>

Install and import the biconomy package from the Particle Network SDK

```sh
yarn add @particle-network/aa
//or
npm install @particle-network/aa
```


## Initialize the SmartAccount

You need to create a Particle project to connect to your app, Visit [Particle Dashboard](https://dashboard.particle.network).

The provider is [EIP-1193: Ethereum Provider JavaScript API ](https://eips.ethereum.org/EIPS/eip-1193), you can use Particle Provider, MetaMask Provider or any EVM wallet provider.

```typescript
import { SmartAccount } from '@particle-network/aa';

//provider: eip1193
const smartAccount = new SmartAccount(provider, {
    projectId: 'particle project id',
    clientKey: 'particle client key',
    appId: 'particle app id',
    aaOptions: {
        accountContracts: {  // 'BICONOMY', 'CYBERCONNECT', 'SIMPLE' is supported now.
            BICONOMY: [
                {
                    version: '1.0.0',
                    chainIds: [x, xx], // optional
                },
                {
                    version: '2.0.0'
                }
            ],
            CYBERCONNECT: [
                {
                    version: '1.0.0'
                }
            ],
            SIMPLE: [
                {
                    version: '1.0.0'
                }
            ],
        },
    },
});

// set current smart account contract
smartAccount.setSmartAccountContract({ name: 'BICONOMY', version: '2.0.0' });

```

## Get Smart Account Address

Once you have connected your EOA signer and created an instance of Smart Account, the address is the public property and remains the same across all EVM chains.

```typescript
// AA address
const address = await smartAccount.getAddress();
// EOA address
const address = await smartAccount.getOwner();
// load account more info.
const accountInfo = await smartAccount.getAccount();
```

## Get Fee Quotes

Before send transactions, you can get fee quotes and display on UI Modal, users can choose which token to use to pay gas fees.

```typescript
const tx = {
    to: '0x...',
    value: '0x...'
}
// or bacth transactions
const txs = [
    {
        to: '0x...',
        value: '0x...'
    },
    {
        to: '0x...',
        value: '0x...'
    }
]
//get fee quotes with tx or txs
const feeQuotesResult = await smartAccount.getFeeQuotes(tx);

// gasless transaction userOp, maybe null
const gaslessUserOp = feeQuotesResult.verifyingPaymasterGasless?.userOp;
const gaslessUserOpHash = feeQuotesResult.verifyingPaymasterGasless?.userOpHash;

// pay with Native tokens: transaction userOp
const paidNativeUserOp = feeQuotesResult.verifyingPaymasterNative?.userOp;
const paidNativeUserOpHash = feeQuotesResult.verifyingPaymasterNative?.userOpHash;

// pay with ERC-20 tokens: fee quotes
const tokenPaymasterAddress = feeQuotesResult.tokenPaymaster.tokenPaymasterAddress;
const tokenFeeQuotes = feeQuotesResult.tokenPaymaster.feeQuotes;

</code></pre>
```

## Build User Operation

Builds a `UserOp` object from the provided array of `Transaction`s. It also accepts optional `feeQuote` and `tokenPaymasterAddress`. Returns a Promise that resolves to the `UserOpBundle`.

```typescript
// build user operation, feeQuote and tokenPaymasterAddress is optional.
const userOpBundle = await smartAccount.buildUserOperation({ tx, feeQuote, tokenPaymasterAddress })
const userOp = userOpBundle.userOp;
const userOpHash = userOpBundle.userOpHash;

```

### Send User Operation

Sends the pre-signed `UserOperation` to the Particle network for execution. Returns a Promise that resolves to a `TransactionHash`.

```typescript
// Some code
const txHash = await smartAccount.sendUserOperation({ userOp, userOpHash });
```

## Wallet Deployment flow

Any gasless or user paid transaction will check whether the wallet is deployed or not. If the wallet is not deployed, the SDK will batch the wallet deployment with the intended transaction/batch transactions. This behaviour is handled within the SDK itself & would require no changes in your code to enable this.

### Deploy Wallet Contract Manual

```typescript
// check the constract is deployed
const isDeploy = await smartAccount.isDeployed();
if (!isDeploy) {
    const txHash = await smartAccount.deployWalletContract();
}
```

## Wrap Provider

If your app has implemented sending transactions, or use web3.js, you can wrap the EIP-1193 provider to quickly implement AA wallet.

```typescript
import { AAWrapProvider, SendTransactionMode, SendTransactionEvent } from '@particle-network/aa';
import Web3 from "web3";

// sendTxMode: UserPaidNative(default), Gasless, UserSelect
const wrapProvider = new AAWrapProvider(smartAccount, SendTransactionMode.UserPaidNative);
// replace any EIP-1193 provider to wrapProvider
const web3 = new Web3(wrapProvider);
//send user paid transaction
await web3.eth.sendTransaction(tx);


// send gassless transaction
const wrapProvider = new AAWrapProvider(smartAccount, SendTransactionMode.Gasless);
const web3 = new Web3(wrapProvider);
await web3.eth.sendTransaction(tx);


// use select pay gas token or gasless
const wrapProvider = new AAWrapProvider(smartAccount, SendTransactionMode.UserSelect);
const web3 = new Web3(wrapProvider);
wrapProvider.once(SendTransactionEvent.Request, (feeQuotesResult) => {
    // let the user select the pay gas ERC-20 token
    wrapProvider.resolveSendTransaction({
        feeQuote: feeQuotesResult.tokenPaymaster.feeQuote[0],
        tokenPaymasterAddress: feeQuotesResult.tokenPaymaster.tokenPaymasterAddress
    });
    
    // or pay with native token
    wrapProvider.resolveSendTransaction(feeQuotesResult.verifyingPaymasterNative);
    
    // or send gasless
    if (feeQuotesResult.verifyingPaymasterGasless) {
        wrapProvider.resolveSendTransaction(feeQuotesResult.verifyingPaymasterGasless);
    }
      
    // or reject send transaction
    wrapProvider.rejectSendTransaction({ message: 'user rejected'});
});
await web3.eth.sendTransaction(tx);

```

## Learn More

* [Docs](https://developers.particle.network/api-reference/aa/introduction)

---
_Source: https://npm.io/package/@particle-network/aa · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
