Tagged

The Era of Account Abstraction

A Developer's Guide to understanding and integrating smart accounts on zkSync Era

Antoine Sparenberg
May 30, 2023

Context

Account abstraction has been gaining significant attention lately, and for good reason - it has the potential to simplify user experience and drive crypto adoption. If you’re still wondering what all the fuss is about, check out “WTF is Account Abstraction” before reading on.

With the launch of zkSync Era which introduces native support for smart accounts, it's crucial for developers to ensure their applications are compatible with smart accounts.

Why native smart account support matters

Without native smart account support (i.e. at the protocol level) it is difficult to implement full account abstraction and reap its benefits to improve user experience and drive wide adoption.

Layer 1 Ethereum and EVM chains do not natively support smart accounts and although contract accounts are the only accounts that can implement arbitrary logic, EOAs are the only type of account that can initiate transactions on these chains.

However, smart accounts in zkSync Era can initiate transactions, like an EOA, but can also have arbitrary logic implemented in them, like a smart contract.

Smart account wallets such as Argent provide their users with a seamless, secure, and efficient experience. However, in order to tap into that user base, dapps must ensure their compatibility with smart accounts.

The good news is that integrating smart accounts is straightforward; there are just two conditions to check. So let's dive in!

How to make your dapp compatible

Being smart account compatible is pretty light. In fact, you might already be compatible without knowing!

1. Use EIP-1271 signature validation in your smart contracts (Solidity) and front-end (JavaScript), instead of using ecrecover directly.

To validate signatures from smart contracts, we recommend using OpenZeppelin's SignatureChecker:

import {SignatureChecker} from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
// ...
using SignatureChecker for address;
// ...
bool isValid = someAddress.isValidSignatureNow(messageHash, signature);

To validate signatures from the front-end, we recommend using Matter Labs' library to abstract the logic away:

import * as zksync from "zksync-web3";

// for signed messages:
const isValid = await zksync.utils.isMessageSignatureCorrect(provider, address, message, signature);
// for typed data:
const promise = await zksync.utils.isTypedDataSignatureCorrect(provider, address, domain, types, value, signature);

2. Avoid using tx.origin which poses a security threat and will trigger a transaction failure with smart accounts.

That’s it! You are now smart account compatible! 🎉

What now ?

Now that you are compatible with smart accounts, you can fully leverage the power of account abstraction on zkSync Era and 10x your User Experience !

Here are a few things to get you started:

Implement Argent Login and tap into the most active zkSync community

With more than 350,000 users on zkSync Era waitlist, Argent mobile wallet is the gateway to the zkSync ecosystem. With Argent Login, you can ensure the best interaction between your dapp and Argent’s wallet.

Leverage account abstraction through multicall and improve UX of your dapp

Using a dapp on Ethereum today requires approving a new transaction for every on-chain interaction, which can be a frustrating, time-consuming, and expensive process, particularly when gas fees are high.

Smart accounts have the ability to group multiple transactions together and execute them at once, greatly improving the user experience of dapps (for example, when you have to send 2 transactions for approve + swap on a DEX).

Argent has a SDK that bundles a multi-transaction flow into a single transaction if the user is connected with a compatible account like Argent, and gracefully degrades to sending multiple transactions if multicall is not supported.

import { multicall } from "@argent/era-multicall";

const calls = [
    await dai.populateTransaction.approve(pool.address, daiAmount),
    await usdc.populateTransaction.approve(pool.address, usdcAmount),
    await pool.populateTransaction.depositPair(dai.address, daiAmount, usdc.address, usdcAmount),
];
const results = await multicall(signer, calls);
Use a paymaster to subsidise your users’ transactions

A paymaster is a smart contract that can subsidise transactions for users, hence abstracting gas fees away. Dapps can use Paymasters to subsidise fees, allow users to pay fees with non-native tokens (e.g. a protocol’s own governance token) or sponsor specific transactions.

Refer to Matter Labs documentation to understand how to implement Paymasters in your transaction flows.

On zkSync Era, Paymasters are natively implemented at prot
Session Keys

Session keys represent a significant UX breakthrough as they enable users to pre-approve the rules governing their interactions with a dapp, allowing them to engage with the platform without requiring a signature for each transaction.

By utilising session keys, users can streamline their interactions with dapps, enjoying a seamless experience without sacrificing security. Ultimately, this breakthrough will contribute to greater adoption of dapps, as more users will be able to interact with them in a safe, efficient manner.

If you want to implement sessions keys in your dapp, please reach out to Argent at dapps@argent.xyz

Workshop with Argent & zkSync

Need a step-by-step guide to make your dapp smart account compatible ? Have a look at this tutorial.

Related Blogs

Part I: WTF is Account Abstraction

Learn why it’s a game changer for crypto's adoption

Part 2: WTF is Account Abstraction

The challenges of bringing Account Abstraction to Ethereum

Part 3: WTF is Account Abstraction

Scaling the UX and security of crypto by 10X

Own It

We use 🍪 cookies to personalise your experience on Argent. Privacy Policy

Accept

HQ London, made with ❤️ across Europe