Using the EIL SDK¶
Demo Repository¶
All code in this tutorial is available in the EIL SDK Demo Repository.
Creating an SDK instance¶
The EIL SDK is a singleton object that has to be properly initialized before it can be used across your TypeScript or JavaScript web application.
It uses the viem:2.39.3 internally and requires an instance of a WalletClient class from Viem or Wagmi to connect to a given network.
This guide assumes a project is using wagmi:2.19.1 in a React 19 web application.
Step 1. Choose the BaseMultichainSmartAccount implementation instance¶
Currently, different Smart Account implementations require different subclasses of BaseMultichainSmartAccount.
The SDK ships with two implementations:
MultiChainSmartAccount- supports pre-EIL Smart Account contracts, requires multiple signatures per cross-chain action.AmbireMultiChainSmartAccount- specific implementation for the experimental EIL-compatible Ambire wallet.
Additionally, we expect multiple third-party implementations to be created in the near future.
This tutorial is based on the AmbireMultiChainSmartAccount implementation.
Step 2. Create the WalletClient to connect to the injected provider¶
import { getAccount, getWalletClient, reconnect } from '@wagmi/core'
async function fetchWalletClient () {
await reconnect(wagmiConfig)
const account = getAccount(wagmiConfig)
if (!account.isConnected || !account.connector) {
throw new Error('Wallet not connected')
}
const walletClient = await getWalletClient(wagmiConfig, {
connector: account.connector,
})
return walletClient
}
Step 3. Create the AmbireMultiChainSmartAccount¶
import { AmbireMultiChainSmartAccount } from '@eil-protocol/accounts'
import { getAccount } from '@wagmi/core'
const ambireBundlerManager = new AmbireBundlerManager(walletClient, new Map<bigint, Address>())
const walletAccount = getAccount(wagmiConfig)?.address ?? zeroAddress
const ambireAccount = new AmbireMultiChainSmartAccount(walletClient, walletAccount, [chainId0, chainId1], ambireBundlerManager)
await ambireAccount.init()
Step 4. Create the EIL SDK instance¶
The CrossChainSdk constructor accepts an optional instance of the CrossChainConfig implementation.
const sdk = new CrossChainSdk();
Making an action¶
Navigate to Creating an Action for more information.
Troubleshooting¶
Connecting the injected Web3 provider (MetaMask, WalletConnect, etc.)¶
When using the injected window.ethereum EIP-1193 provider with MultiChainSmartAccount, there are a number of caveats to be aware of.
- Ensure the Wallet is authorized and connected to the webpage. You may need to poll the injected object to be fully ready or prompt the user for action.
- The "network" that is selected in the Wallet UI does not affect the EIL SDK signature, and the EIL UserOperation will be used on the network specified by the EIL SDK.
- The address of the Smart Account is different from the address of the account owner, which is expected to be an EOA. This means that the assets controlled by the owner EOA are not accessible by the Smart Account by default.