Last active
June 27, 2023 10:04
-
-
Save Spetsnaz-Dev/4e78eeda87108eea3a855531d31bc236 to your computer and use it in GitHub Desktop.
Get counterfactual address of an AA Smart Wallet before deployment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BigNumberish, ethers } from 'ethers' | |
import { KernelFactory__factory, EntryPoint__factory } from '@zerodevapp/contracts-new' | |
const ENTRYPOINT_ADDRESS = '0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789' | |
const KERNEL_FACTORY_ADDRESS = '0x4E4946298614FC299B50c947289F4aD0572CB9ce' | |
async function getKernelWalletAddress(factoryAddress: string, entryPointAddress: string, provider: ethers.providers.BaseProvider, signerWalletAddress: string, index: BigNumberish): Promise<string> { | |
const factory = KernelFactory__factory.connect( | |
factoryAddress, | |
provider | |
); | |
const entryPoint = EntryPoint__factory.connect(entryPointAddress, provider); | |
try { | |
const initCode = ethers.utils.hexConcat([ | |
factory.address, | |
factory.interface.encodeFunctionData("createAccount", [ | |
signerWalletAddress, | |
index | |
]), | |
]); | |
await entryPoint.callStatic.getSenderAddress(initCode); | |
throw new Error("getSenderAddress: unexpected result"); | |
} catch (error: any) { | |
const addr = error?.errorArgs?.sender; | |
if (!addr) throw error; | |
return addr; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment