This Quickstart guides you through creating your first modular wallet smart
account and sending a gasless transaction using the modular wallets SDKs for
Web, iOS, or Android. For a complete web app implementation, refer
to the
Circle Smart Account example
in the modular wallets web SDK.
Note:Circle provides a robust built-in indexing service optimized for subscribed
transactions per wallet. You can set up
webhook subscriptions on the Circle
Console to receive notifications for transfer activities or user operations. To
retrieve data from our Indexing Service through your backend, use an API Key to
authenticate RESTful API requests.
The Swift Package Manager is a tool for
automating the distribution of Swift code and is integrated into the swift
compiler.Once you have your Swift package set up, adding CircleModularWalletsCore as a
dependency is as easy as adding it to the dependencies value of your
Package.swift or the Package list in Xcode.
Add the maven setting values in local.properties file:
Properties
Copy
Ask AI
mwsdk.maven.url=https://maven.pkg.github.com/circlefin/modularwallets-android-sdkmwsdk.maven.username=<GITHUB_USERNAME># Fine-grained personal access tokens or classic with package write permission.mwsdk.maven.password=<GITHUB_PAT>
You can get started with the sample code below which showcases basic Modular
Wallets capabilities, including Circle Smart Account, passkey, paymaster, and
bundler services to send a gasless transaction with passkey signing.
import { toPasskeyTransport, toWebAuthnCredential,} from '@circle-fin/modular-wallets-core'// 0. retrieve client key and client url from environment varsconst clientKey = import.meta.env.VITE_CLIENT_KEY as stringconst clientUrl = import.meta.env.VITE_CLIENT_URL as string// 1. register or login with a passkey and// Create a Passkey Transport from client keyconst passkeyTransport = toPasskeyTransport(clientUrl, clientKey)const credential = await toWebAuthnCredential({ transport: passkeyTransport, mode: WebAuthnMode.Register, //or WebAuthnMode.Login if login username: 'your-username' //replace with actual username})
Create a Circle Smart Account using the transport client and the owner’s
credentials. Then, create a bundler client to send user operations for the
specified blockchain. The example below uses the polygonAmoy chain.
Copy
Ask AI
import { toCircleSmartAccount } from "@circle-fin/modular-wallets-core";import { createBundlerClient, toWebAuthnAccount,} from "viem/account-abstraction";// 4. create a circle smart accountconst smartAccount = await toCircleSmartAccount({ client, owner: toWebAuthnAccount({ credential, }),});// 5. create a bundler clientconst bundlerClient = createBundlerClient({ smartAccount, chain: polygonAmoy, transport: modularTransport,});
Encapsulate the transaction within a user operation (userOp) and send it to the
bundler. The bundler then initiates the transaction on behalf of the sender and
forwards the transaction receipt back upon request.
Note:On mobile platforms, iOS and Android offer at least a second option to
send a transaction using the encodeTransfer() method. In the code below,
ensure you select either Option 1 or Option 2 based on your
requirements.
Copy
Ask AI
import { encodeTransfer } from "@circle-fin/modular-wallets-core";// 6. Send a user operation to the bundler.// Here we send 1 USDC to a random addressconst USDC_CONTRACT_ADDRESS = "0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582"; //Polygon Amoy testnetconst USDC_DECIMALS = 6;const userOpHash = await bundlerClient.sendUserOperation({ calls: [encodeTransfer(to, USDC_CONTRACT_ADDRESS, 100000n)], paymaster: true,});// 7. wait for transaction receiptconst { receipt } = await bundlerClient.waitForUserOperationReceipt({ hash: userOpHash,});