Skip to main content

🧡 Recover a Lost Account and Tokens

Welcome to the complete guide for the "Recover a Lost Account" workflow for the Token City Blockchain API.

This workflow enables you to recover a lost blockchain account along with its associated tokens, by generating the appropriate EIP712 signature and executing the recovery operation.

🌟 Objective: Securely recover a user's blockchain account and its token assets in case of account loss or compromise.


πŸ“š OpenAPI Documentation​


✨ Workflow Summary​

This workflow automates the recovery process of a lost account on the Token City blockchain:

  1. πŸ”Ή Generate typed data for EIP712 signature for the account recovery.
  2. πŸ”Ή Sign the generated EIP712 object using an authorized recovery agent account.
  3. πŸ”Ή Recover the lost account and its tokens using the signed data.
  4. πŸ”Ή Monitor recovery transaction status via webhook.

πŸ“‹ Workflow Steps Table​

StepAPI OperationMethodParametersOutputsDescription
Generate EIP712 Typed DataPOST /erc3643/{tokenId}/recovery-address/eip712-typed-dataPOSTtokenId, oldAccount, newAccountEIP712 Typed DataPrepares the typed data needed for EIP712 signing
Sign EIP712 ObjectPOST /accounts/{accountId}/signEip712POSTpasscode, eip712Objecteip712SignatureSigns the typed EIP712 object with an authorized recovery agent account
Recover Lost AccountPOST /erc3643/{tokenId}/recovery-addressPOSTtokenId, oldAccount, newAccount, identity, nonce, signatureTransaction IDExecutes the account recovery and transfers tokens
Monitor Recovery StatusWebhook subscription--TX_MINED or TX_FAILEDConfirms recovery completion via webhook notification

🎨 Workflow Visualizations​

🌊 Mermaid Sequence Diagram​


πŸ“ Step-by-Step Implementation​

Step 1: Generate EIP712 Typed Data for Recovery​

Generate the structured data required for signing the recovery operation.

Endpoint: POST /erc3643/{tokenId}/recovery-address/eip712-typed-data

Path Parameters:

  • tokenId: UUID of the token from which to recover assets

Request Body:

{
"oldAccount": "0xdE394eD7ac8Ca7E5Ed89F54BA3B02Aed7aD12343",
"newAccount": "0xbe188D6641E8b680743A4815dFA0f6208038960F"
}

Request Parameters:

  • oldAccount: Address of the wallet to be recovered
  • newAccount: Address of the new wallet

Response:

{
{
"passcode": "123456",
"eip712Object": {
"types": {
"EIP712Domain": [
{ "name": "name", "type": "string" },
{ "name": "version", "type": "string" },
{ "name": "chainId", "type": "uint256" },
{ "name": "verifyingContract", "type": "address" }
],
"RecoverAddress": [
{ "name": "oldAccount", "type": "address" },
{ "name": "newAccount", "type": "address" },
{ "name": "identity", "type": "address" }
]
},
"primaryType": "RecoverAddress",
"domain": {
"name": "TokenCityRecovery",
"version": "1.0.0",
"chainId": 137,
"verifyingContract": "0xTokenContractAddress..."
},
"message": {
"oldAccount": "0xdE394eD7ac8Ca7E5Ed89F54BA3B02Aed7aD12343",
"newAccount": "0xbe188D6641E8b680743A4815dFA0f6208038960F",
"identity": "0x5Bbfb5dAB27c0b32FDdAa6705d8B23E070a7613e",
"nonce": "10"
}
}
}
}

Step 2: Sign the EIP712 Typed Data​

Sign the typed data using an authorized recovery account (ERIR / Tc Validator Account).

Endpoint: POST /accounts/{accountId}/signEip712

Path Parameters:

  • accountId: WalletAddress of authorized recovery agent account

Request Body:

{
"passcode": "123456",
"eip712Object": {
"types": {
"EIP712Domain": [
{ "name": "name", "type": "string" },
{ "name": "version", "type": "string" },
{ "name": "chainId", "type": "uint256" },
{ "name": "verifyingContract", "type": "address" }
],
"RecoverAddress": [
{ "name": "oldAccount", "type": "address" },
{ "name": "newAccount", "type": "address" },
{ "name": "identity", "type": "address" }
]
},
"primaryType": "RecoverAddress",
"domain": {
"name": "TokenCityRecovery",
"version": "1.0.0",
"chainId": 137,
"verifyingContract": "0xTokenContractAddress..."
},
"message": {
"oldAccount": "0xdE394eD7ac8Ca7E5Ed89F54BA3B02Aed7aD12343",
"newAccount": "0xbe188D6641E8b680743A4815dFA0f6208038960F",
"identity": "0x5Bbfb5dAB27c0b32FDdAa6705d8B23E070a7613e",
"nonce": "10"
}
}
}

Response:

{
"eip712Signature": "0x2d98d5a2b62d9fa3c599227f6106462c0c8158e1ae558efa0037a74c354565803eb82ecf16a89dc6a466d6adab39d3fc3bc50ea6950601a02f58cfa0cd312c6d1b"
}

Step 3: Execute Account Recovery​

Execute the recovery operation with the signed data to transfer tokens to the new wallet.

Endpoint: POST /erc3643/{tokenId}/recovery-address

Path Parameters:

  • tokenId: UUID of the token from which to recover assets

Request Body:

{
"oldAccount": "0xdE394eD7ac8Ca7E5Ed89F54BA3B02Aed7aD12343",
"newAccount": "0xbe188D6641E8b680743A4815dFA0f6208038960F",
"identity": "0x5Bbfb5dAB27c0b32FDdAa6705d8B23E070a7613e",
"nonce": "1",
"signature": "0x2d98d5a2b62d9fa3c599227f6106462c0c8158e1ae558efa0037a74c354565803eb82ecf16a89dc6a466d6adab39d3fc3bc50ea6950601a02f58cfa0cd312c6d1b"
}

Request Parameters:

  • oldAccount: Address of the wallet to be recovered
  • newAccount: Address of the new wallet
  • identity: Address of the identity contract from which the old wallet will be removed and the new one added
  • nonce: Unique number per request to prevent replay attacks
  • signature: EIP712 signature of the request

Response:

{
"id": "567e7895-c76b-12d3-a456-426614174000"
}

Step 4: Monitor Recovery Status​

Subscribe to webhooks or poll transaction status to confirm recovery completion.

TX_MINED Webhook:

{
"type": "TX_MINED",
"event": {
"txUUID": "tx_recovery_123e4567-e89b-12d3-a456-426614174000",
"txHash": "0xb5c8bd9430b6cc87a0e2fe110ece6bf527fa4f170a4bc8cd032f768fc5219838",
"timestamp": 1634567890
}
}

TX_FAILED Webhook:

{
"type": "TX_FAILED",
"event": {
"txUUID": "tx_recovery_123e4567-e89b-12d3-a456-426614174000",
"reason": "Unauthorized recovery agent",
"timestamp": 1634567890
}
}

πŸ’‘ Key Concepts​

What is Account Recovery?​

Account recovery is a compliance feature in ERC-3643 tokens that allows:

  • Transfer of tokens from a lost/compromised wallet to a new wallet
  • Maintains the investor's on-chain identity
  • Requires authorization from token agents or recovery agents
  • Preserves compliance and KYC verifications
  • Provides an audit trail for regulatory purposes

Recovery Authorization​

Only authorized recovery agents can execute recoveries:

  • Accepted Validators: Designated by the token issuer with recovery permissions (ERIR / TC Validator Wallet)

Identity Preservation​

During recovery:

  • The on-chain identity remains the same
  • All KYC/AML claims stay valid
  • Token balance is transferred atomically to the new wallet
  • Compliance status is maintained
  • Transfer restrictions still apply to the new wallet

When to Use Recovery​

Recovery is appropriate for:

  • Lost pincode and emergencyCode: Investor permanently lost access to wallet
  • Compromised Accounts: Wallet security breached
  • Technical Issues: Wallet software corruption

⚠️ Important Notes​

  1. Authorization Required: Only token agents with recovery permissions can execute recoveries
  2. Identity Link: The identity address must match the old wallet's registered identity
  3. New Wallet Setup: New wallet should be created and registered before recovery
  4. Balance Transfer: All token balance is moved atomically; freezed and unfreezed also
  5. Irreversible: Recovery transactions cannot be undone once mined
  6. Compliance: New wallet inherits all compliance requirements and restrictions
  7. Verification: Carefully verify typed data matches exactly before signing
  8. Documentation: Maintain records of recovery for audit purposes
  9. Nonce: Each recovery request requires a unique nonce to prevent replay attacks


πŸ†˜ Troubleshooting​

Recovery Transaction Failed​

If recovery fails, verify:

  • βœ“ Signer has recovery agent permissions on the token
  • βœ“ Old account address is correct and has non-zero token balance
  • βœ“ New account address is valid and different from old account
  • βœ“ Identity address matches the old account's registered identity
  • βœ“ New account has been registered in identity registry
  • βœ“ Signature is valid and matches typed data exactly
  • βœ“ Nonce is unique and hasn't been used before
  • βœ“ Sufficient gas is available for the transaction

Unauthorized Recovery Agent​

If authorization fails:

  • βœ“ Verify signer account is a recovery agent on the token contract
  • βœ“ Ensure recovery agent role hasn't been revoked
  • βœ“ Confirm signer account matches the one used for signing

Signature Validation Failed​

If signature is rejected:

  • βœ“ Typed data structure matches exactly the response from Step 1
  • βœ“ No modifications were made to the typed data before signing
  • βœ“ Correct account was used for signing (recovery agent)
  • βœ“ EIP712 domain parameters match (chainId, verifyingContract)
  • βœ“ Message fields are in correct format (addresses, etc.)

πŸ“š Additional Resources​


πŸ’Ό Use Case Examples​

Example 1: Investor Lost Private Key​

Scenario: An investor lost their hardware wallet containing 1000 security tokens.

Initial State:

  • Lost wallet: 0xLost...123
  • Token balance: 1000 tokens
  • On-chain identity: 0xIdentity...abc
  • New wallet: Not yet created

Step 1 - Create New Wallet:

POST /accounts

New wallet created: 0xNew...456

Step 2 - Generate Recovery Typed Data:

{
"oldAccount": "0xLost...123",
"newAccount": "0xNew...456"
}

Response:

{
"passcode": "123456",
"eip712Object": {
"types": {
"EIP712Domain": [
{ "name": "name", "type": "string" },
{ "name": "version", "type": "string" },
{ "name": "chainId", "type": "uint256" },
{ "name": "verifyingContract", "type": "address" }
],
"RecoverAddress": [
{ "name": "oldAccount", "type": "address" },
{ "name": "newAccount", "type": "address" },
{ "name": "identity", "type": "address" }
]
},
"primaryType": "RecoverAddress",
"domain": {
"name": "TokenCityRecovery",
"version": "1.0.0",
"chainId": 137,
"verifyingContract": "0xTokenContractAddress..."
},
"message": {
"oldAccount": "0xdE394eD7ac8Ca7E5Ed89F54BA3B02Aed7aD12343",
"newAccount": "0xbe188D6641E8b680743A4815dFA0f6208038960F",
"identity": "0x5Bbfb5dAB27c0b32FDdAa6705d8B23E070a7613e",
"nonce": "10"
}
}
}

Step 3 - Recovery Agent Signs: Token agent with recovery permissions signs the EIP712 typed data

Step 4 - Execute Recovery:

{
"oldAccount": "0xLost...123",
"newAccount": "0xNew...456",
"identity": "0xIdentity...abc",
"nonce": "1",
"signature": "0x2d98d5a..."
}

Response: { "id": "567e7895-c76b-12d3-a456-426614174000" }

Step 5 - Confirmation: TX_MINED webhook received confirming 1000 tokens moved to new wallet

Result: Investor successfully recovered access to 1000 tokens while maintaining compliance status and identity.