Skip to content

Commit a7b77f2

Browse files
committed
update readme
1 parent 707023c commit a7b77f2

File tree

1 file changed

+63
-39
lines changed

1 file changed

+63
-39
lines changed

README.md

Lines changed: 63 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Variance SDK
22

3-
Variance is a Dart SDK designed to simplify interaction with Ethereum-based blockchains and enables flutter developers to implement account abstraction with minimal efforts. It provides functionalities such as encoding and decoding ABI data, handling Ethereum transactions, working with ERC20 and ERC721 tokens, and managing Ethereum smart accounts.
3+
Variance is an Account Abstraction Developer toolkit that is designed to simplify the development of Ethereum smart accounts and Entrypoint interactions. It relies on the [Web3dart](https://pub.dev/packages/web3dart) library.
44

55
## Features
66

77
- **ABI Encoding/Decoding:** Easily encode and decode ABI data for Ethereum smart contract and Entrypoint interactions.
88
- **Transaction Handling:** Simplify the process of creating and sending UserOperations.
99
- **Token Operations:** Work with ERC20 and ERC721 tokens, including transfer and approval functionalities.
10-
- **Web3 Functionality:** Interact with Ethereum nodes and bundlers using abstracted methods over, `eth_sendTransaction`, and `eth_sendUserOperation`.
11-
- **SecP256r1 Signatures:** Sign transactions with SecP256r1 signatures.
10+
- **Web3 Functionality:** Interact with Ethereum nodes and bundlers.
11+
- **SecP256r1 Signatures:** Sign transactions with Passkeys.
1212

1313
## Getting Started
1414

@@ -19,50 +19,45 @@ open your terminal and run the following command:
1919
```sh
2020
flutter pub add variance_dart
2121
flutter pub add web3_signers
22-
23-
# optionally
2422
flutter pub add web3dart
2523
```
2624

2725
### Usage
2826

2927
```dart
30-
// Import the package
28+
// Import the packages
3129
import 'package:web3_signers/web3_signers.dart';
3230
import 'package:variance_dart/variance_dart.dart';
33-
34-
// optionally
3531
import 'package:web3dart/web3dart.dart';
3632
```
3733

3834
### Chain Configuration
3935

4036
```dart
41-
const String rpcUrl = 'http://localhost:8545';
42-
const String bundlerUrl = 'http://localhost:3000/rpc';
43-
const Uint256 salt = const Uint256.zero;
37+
static const rpc = "https://api.pimlico.io/v2/84532/rpc?apikey=API_KEY";
38+
final Uint256 salt = Uint256.zero;
4439
45-
final Chain chain = Chains.getChain(Network.localhost)
46-
..jsonRpcUrl = rpcUrl
47-
..bundlerUrl = bundlerUrl;
40+
final Chain chain = Chains.getChain(Network.baseTestnet)
41+
..accountFactory = Constants.lightAccountFactoryAddressv07
42+
..bundlerUrl = rpc
43+
..paymasterUrl = rpc;
4844
```
4945

50-
> There are 8 available networks: ethereum, polygon, optimism, base, arbitrumOne, linea, opBnB and scroll. 3 available testnets: sepolia, mumbai and baseTestent. You can also develop on localHost.
46+
> For Safe Accounts, use `Constants.safeProxyFactoryAddress` as the account factory.
47+
> There are 8 available networks: ethereum, polygon, optimism, base, arbitrum, linea, fuse and scroll. 2 available testnets: sepolia and baseTestent.
5148
52-
Additionally, you can specify a different Entrypoint address. By default, the entrypoin v0.6 is used.
49+
Additionally, you can specify a different Entrypoint address. By default, the entrypoin v0.7 is used. If you wish to use v0.6, you can do so as follows:
5350

5451
```dart
55-
final EntryPointAddress entrypointAddress = EntryPointAddress.v07;
52+
final EntryPointAddress entrypointAddress = EntryPointAddress.v06;
5653
chain.entrypoint = entrypointAddress;
57-
```
5854
59-
Also if wish to use paymasters with your smart wallet you can do so by specifying the endpoint of the paymaster. By default the paymaster is set to null. This would add a paymaster Plugin to the smart wallet.
60-
61-
```dart
62-
final String paymasterUrl = 'https://api.pimlico.io/v2/84532/rpc?apikey=...';
63-
chain.paymasterUrl = paymasterUrl;
55+
// OR append it to the chain
56+
..entrypoint = EntryPointAddress.v06;
6457
```
6558

59+
> By default the paymaster is set to null. If wish to use paymasters with your smart wallet you can do so by specifying the rpc endpoint of the paymaster. This would add a paymaster Plugin to the smart wallet.
60+
6661
If you have additional context for the paymaster, you will be able to add it to the smart wallet after creation or before initiating a transaction.
6762

6863
```dart
@@ -75,10 +70,18 @@ In order to create a smart wallet client you need to set up a signer, which will
7570

7671
> You have to use the correct signer for the type of account you want to create.
7772
78-
1. `PrivateKeys` - use with light accounts and safe accounts only
79-
2. `Passkey` - use with p256 smart accounts and safe Passkey accounts only
80-
3. `EOA Wallet (Seed Phrases)` - use with light smart accounts and safe accounts only
81-
4. `HardWare Signers (Secure Enclave/Keystore)` - use with p256 smart accounts only
73+
1. `PrivateKeys` - use with light accounts and safe accounts
74+
2. `Passkey` - use with safe Passkey accounts only
75+
3. `EOA Wallet` - use with light smart accounts and safe accounts
76+
77+
For more information, please check out the [web3signers](https://pub.dev/packages/web3_signers) package documentation.
78+
79+
##### **What is the difference between `PrivateKeys` and `EOA Wallet`?**
80+
81+
- The `PrivateKey` signer generates only a single private key for use with a smart account. The private key requires a password, and the private key can be serialized into JSON format for storage.
82+
- The `EOA Wallet` signer generates a HD wallet with multiple accounts for use with a smart account. Additionally the `EOA Wallet` signer allows the smart account to sign transactions with different accounts by specifying the account index.
83+
84+
>With `EOA Wallet` signer, users receive the mnemonic phrase but with `PrivateKey` signer they dont.
8285
8386
### Smart Wallet Factory
8487

@@ -90,36 +93,57 @@ final SmartWalletFactory smartWalletFactory = SmartWalletFactory(chain, signer);
9093

9194
#### To Create an Alchemy Light Account
9295

96+
The [Alchemy Light Account](https://accountkit.alchemy.com/smart-contracts/light-account) requires the signer to have a prefix. When creating a web3_signer for your smart wallet make sure to provide a `Uint8` value prefix. This will be appended to the signature generated by the signers.
97+
Example:
98+
9399
```dart
100+
const prefix = const SignatureOptions(prefix: [0])
101+
final signer = EOAWallet.createWallet(WordLength.word_12, prefix);
102+
final smartWalletFactory = SmartWalletFactory(chain, signer);
103+
94104
final Smartwallet wallet = await smartWalletFactory.createAlchemyLightAccount(salt);
95105
print("light account wallet address: ${wallet.address.hex}");
96106
```
97107

98-
#### To create a P256 Smart Account (Secure Enclave/Keystore)
108+
#### To create a [Safe](https://safe.global) Smart Account
99109

100110
```dart
101-
final Smartwallet wallet = await smartWalletFactory.createP256Account(keypair, salt);
102-
print("p256 wallet address: ${wallet.address.hex}");
111+
// No prefix is required. word_12 is the default
112+
final signer = EOAWallet.createWallet();
113+
final smartWalletFactory = SmartWalletFactory(chain, signer);
114+
115+
final Smartwallet wallet = await smartWalletFactory.createSafeAccount(salt);
116+
print("safe wallet address: ${wallet.address.hex}");
103117
```
104118

105-
Your keypair must be either be the `PassKeyPair` or `P256Credential` return when registering with your secp256r1 signer.
106-
Additionally, you can pass a recovery address to the `createP256Account` method.
119+
#### To create a [Safe](https://safe.global) Smart Account with Passkey
107120

108121
```dart
109-
final Smartwallet wallet = await smartWalletFactory.createP256Account(keypair, salt, recoveryAddress);
122+
final sharedWebauthnSigner = EthereumAddress.fromHex("0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9");
123+
final options = PassKeysOptions(
124+
...
125+
sharedWebauthnSigner: sharedWebauthnSigner,);
126+
127+
final signer = PassKeySigner(options: options);
128+
final smartWalletFactory = SmartWalletFactory(chain, signer);
129+
final keypair = await signer.register(name, displayName); // email can be used in place of name
130+
131+
final Smartwallet wallet = await smartWalletFactory.createSafeAccountWithPasskey(
132+
keypair, salt, sharedWebauthnSigner);
110133
print("p256 wallet address: ${wallet.address.hex}");
111134
```
112135

113-
#### To create a [Safe](https://safe.global) Smart Account
136+
> Your keypair must be a `PassKeyPair` object received when registering with your `PasskeySigner` signer.
137+
> Keypair can serialized and stored by the app
138+
139+
Additionally, you can pass a `p256Verifier` address to the `createSafeAccountWithPasskey` method, by default the [RIP-7212](https://github.com/ethereum/RIPs/blob/master/RIPS/rip-7212.md) precompile is used.
114140

115141
```dart
116-
final Smartwallet wallet = await smartWalletFactory
117-
.createSafeAccount(salt);
118-
print("safe wallet address: ${wallet.address.hex}");
142+
final Smartwallet wallet = await smartWalletFactory.createSafeAccountWithPasskey(
143+
keypair, salt, sharedWebauthnSigner, p256Verifier);
144+
print("p256 wallet address: ${wallet.address.hex}");
119145
```
120146

121-
> Safe SecP256r1 signers can not be used with this SDK yet.
122-
123147
### Interacting with the Smart Wallet
124148

125149
```dart

0 commit comments

Comments
 (0)