创建并发送用户操作的 SDK
这个软件包为使用用户操作提供了2个API:
- 低级"walletAPI"
- 高级别提供者
低级 API :
基础WalletAPI
为合同钱包创建用户操作的抽象基础类.
简单账户
实施BaseWalletAPI,为简易Wallet的账户-汇总样本.
owner = provider.getSigner()
const walletAPI = new SimpleAccountAPI({
provider,
entryPointAddress,
owner,
factoryAddress
})
const op = await walletAPI.createSignedUserOp({
target: recipient.address,
data: recipient.interface.encodeFunctionData('something', ['hello'])
})
高级提供者 API
一个不需要不同钱包扩展的简化模式. 取而代之的是,目前提供商的账户被作为钱包所有者使用,称其"签名消息"操作.
这只能用于使用 EIP-191 ("Ethereum Signed Message" ) 签名的钱包( 就像我们的样本SimpleWallet) 另外,UX也不大(用户被要求在散列上签名,甚至钱包地址也没有提及,只有签名者)
import { wrapProvider } from '@account-abstraction/sdk'
//use this account as wallet-owner (which will be used to sign the requests)
const aaSigner = provider.getSigner()
const config = {
chainId: await provider.getNetwork().then(net => net.chainId),
entryPointAddress,
bundlerUrl: 'http://localhost:3000/rpc'
}
const aaProvider = await wrapProvider(provider, config, aaSigner)
const walletAddress = await aaProvider.getSigner().getAddress()
// send some eth to the wallet Address: wallet should have some balance to pay for its own creation, and for calling methods.
const myContract = new Contract(abi, aaProvider)
// this method will get called from the wallet address, through account-abstraction EntryPoint
await myContract.someMethod()