Skip to main content

Axir Social Recovery Interaction Guide

This guide provides examples of how to interact with the AxirSocialRecovery contract using various JavaScript snippets.

Installing the Social Recovery Module​

To install the social recovery module on a smart wallet, use the following snippet. Ensure you have the correct address, module type, threshold, and guardians.

await smartWalletAccount.installModule(
SOCIAL_RECOVERY_MODULE.address,
SOCIAL_RECOVERY_MODULE.moduleType,
[
{ type: "uint256", value: threshold },
{
type: "address[]",
value: guardians,
},
],
undefined,
usePaymaster,
paymasterType
);

Getting the Recovery Hash​

To get the recovery hash, use the getHash function from the AxirSocialRecovery contract. This hash will be used to verify the recovery process.

const hash = await readContract(config, {
abi: SOCIAL_RECOVERY_MODULE_ABI,
address: SOCIAL_RECOVERY_MODULE_ADDRESS,
functionName: "getHash",
args: [
ethers.getAddress(axrWalletAddress),
ethers.getAddress(newOwner),
],
});

Signing the Recovery Hash​

Once you have the hash, you can sign it using the following snippet. This signed hash will be used to initiate the recovery process.

await signMessage({
message: { raw: hash },
});

Checking Module Initialization​

Before initiating the recovery process, ensure the module is initialized and check the threshold value. Use the following snippets:

const isInitialized = await readContract(config, {
address: SOCIAL_RECOVERY_MODULE_ADDRESS,
abi: SOCIAL_RECOVERY_MODULE_ABI,
functionName: "isInitialized",
args: [ethers.getAddress(walletAddress)],
});

const thresholdValue = await readContract(config, {
address: SOCIAL_RECOVERY_MODULE_ADDRESS,
abi: SOCIAL_RECOVERY_MODULE_ABI,
functionName: "thresholds",
args: [ethers.getAddress(walletAddress)],
});

Initiating the Recovery Process​

To initiate the recovery process, use the following snippet. Provide the wallet address, new owner, and signatures from the guardians.

await writeContract({
address: SOCIAL_RECOVERY_MODULE_ADDRESS,
abi: SOCIAL_RECOVERY_MODULE_ABI,
functionName: "initiateRecovery",
args: [walletAddress, newOwner, signatures],
});

Executing the Recovery​

After the recovery delay has passed, execute the recovery process using the following snippet.

await writeContract({
address: SOCIAL_RECOVERY_MODULE_ADDRESS,
abi: SOCIAL_RECOVERY_MODULE_ABI,
functionName: "executeRecovery",
args: [walletAddress],
});

Summary​

By following these steps, you can install the social recovery module, generate and sign the recovery hash, check module initialization, initiate the recovery process, and execute the recovery. This ensures a secure and verifiable process for recovering wallet ownership through a consensus of guardians.

Feel free to reach out if you have any questions or need further assistance!