variance_dart

Creator: coderz1093

Last updated:

0 purchases

variance_dart Image
variance_dart Images

Languages

Categories

Add to Cart

Description:

variance dart

Variance SDK #
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.
Features #

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

Getting Started #
Installation #
open your terminal and run the following command:
flutter pub add variance_dart
flutter pub add web3_signers

# optionally
flutter pub add web3dart
copied to clipboard
Usage #
// Import the package
import 'package:web3_signers/web3_signers.dart';
import 'package:variance_dart/variance_dart.dart';

// optionally
import 'package:web3dart/web3dart.dart';
copied to clipboard
Chain Configuration #
const String rpcUrl = 'http://localhost:8545';
const String bundlerUrl = 'http://localhost:3000/rpc';
const Uint256 salt = const Uint256.zero;

final Chain chain = Chains.getChain(Network.localhost)
..jsonRpcUrl = rpcUrl
..bundlerUrl = bundlerUrl;
copied to clipboard

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.

Additionally, you can specify a different Entrypoint address. By default, the entrypoin v0.6 is used.
final EntryPointAddress entrypointAddress = EntryPointAddress.v07;
chain.entrypoint = entrypointAddress;
copied to clipboard
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.
final String paymasterUrl = 'https://api.pimlico.io/v2/84532/rpc?apikey=...';
chain.paymasterUrl = paymasterUrl;
copied to clipboard
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.
wallet.plugin<Paymaster>('paymaster').context = {'key': 'value'};
copied to clipboard
Signers #
In order to create a smart wallet client you need to set up a signer, which will sign useroperation hashes to be verified onchain. Only signers available in the web3signers package can be used.

You have to use the correct signer for the type of account you want to create.


PrivateKeys - use with simple accounts and safe accounts only
Passkey - use with p256 smart accounts and safe Passkey accounts only
EOA Wallet (Seed Phrases) - use with simple smart accounts and safe accounts only
HardWare Signers (Secure Enclave/Keystore) - use with p256 smart accounts only

Smart Wallet Factory #
The smart wallet factory handles the creation of smart wallet instances. Make sure you have created a signer from the previous step.
final SmartWalletFactory smartWalletFactory = SmartWalletFactory(chain, signer);
copied to clipboard
To Create a Simple Smart Account
final Smartwallet wallet = await smartWalletFactory.createSimpleAccount(salt);
print("simple wallet address: ${wallet.address.hex}");
copied to clipboard
To create a P256 Smart Account (Secure Enclave/Keystore)
final Smartwallet wallet = await smartWalletFactory.createP256Account(keypair, salt);
print("p256 wallet address: ${wallet.address.hex}");
copied to clipboard
Your keypair must be either be the PassKeyPair or P256Credential return when registering with your secp256r1 signer.
Additionally, you can pass a recovery address to the createP256Account method.
final Smartwallet wallet = await smartWalletFactory.createP256Account(keypair, salt, recoveryAddress);
print("p256 wallet address: ${wallet.address.hex}");
copied to clipboard
To create a Safe Smart Account
final Smartwallet wallet = await smartWalletFactory
.createSafeAccount(salt);
print("safe wallet address: ${wallet.address.hex}");
copied to clipboard

Safe SecP256r1 signers can not be used with this SDK yet.

Interacting with the Smart Wallet #
// retrieve the balance of a smart wallet
final EtherAmount balance = await wallet.balance;
print("account balance: ${balance.getInWei}");

// retrive the account nonce
final Uint256 nonce = await wallet.nonce;
print("account nonce: ${nonce.toInt()}");

// check if a smart wallet has been deployed
final bool deployed = await wallet.deployed;
print("account deployed: $deployed");

// get the init code of the smart wallet
final String initCode = wallet.initCode;
print("account init code: $initCode");

// perform a simple transaction (send ether to another account)
// account must be prefunded with native token. paymaster is not yet implemented
await wallet.send(
EthereumAddress.fromHex(
"0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"), // receive address
EtherAmount.fromInt(EtherUnit.ether, 0.7142), // 0.7142 ether
);
copied to clipboard
For detailed usage and examples, refer to the documentation. Additional refer to the example for use in a flutter app.
API Reference #
Detailed API reference and examples can be found in the API reference.
Contributing #
We are committed to maintaining variance as an open source sdk, take a look at existing issues, open a pull request etc.
License #
This project is licensed under the BSD-3-Clause - see the LICENSE file for details.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.