Transfer ICP from subaccount using Rosetta API

Hello all IC devs

I was trying to transfer ICP coin through Rosetta API, it was working as expected when my sender account is default account. However, subaccount did not work as the same.

lets say I have two account id from a same principal

  1. Default Account: a08f87a4699df926c0de647a791b9c4e8a3928e33db81ba4b92d844c7f77d757
  2. Subaccount: 2d1a60cd2bd0915f94573a59f268403d7a6e06be0a711735c418a14f4d72efd9

I followed /construction/payloads to create request, and added additional “sub_account” property under account object. Here is my sample request object

{
  "public_keys": [{
      "hex_bytes": "xxx",
      "curve_type": "edwards25519"
  }],
  "operations": [
    {
      "operation_identifier": { "index": 0 },
      "type": "TRANSACTION",
      "account": {
        "address": "a08f87a4699df926c0de647a791b9c4e8a3928e33db81ba4b92d844c7f77d757",
        "sub_account": {
          "address": "2d1a60cd2bd0915f94573a59f268403d7a6e06be0a711735c418a14f4d72efd9"
        }
      },
      "amount": {
        "value": "-100000",
        "currency": { "symbol": "ICP", "decimals": 8 }
      }
    },
    {
      "operation_identifier": { "index": 1 },
      "type": "TRANSACTION",
      "account": {
        "address": "f0d6ecc4116e9542be25f399a08a22d62584e344cd1ea5344caac93f622beb6f"
      },
      "amount": {
        "value": "100000",
        "currency": { "symbol": "ICP", "decimals": 8 }
      }
    },
    {
      "operation_identifier": { "index": 2 },
      "type": "FEE",
      "account": {
        "address": "a08f87a4699df926c0de647a791b9c4e8a3928e33db81ba4b92d844c7f77d757",
        "sub_account": {
          "address": "2d1a60cd2bd0915f94573a59f268403d7a6e06be0a711735c418a14f4d72efd9"
        }
      },
      "amount": {
        "value": "-10000",
        "currency": { "symbol": "ICP", "decimals": 8 }
      }
    }
  ]
}

after that i just followed the instruction, sign, /construction/combine, and /construction/submit, but the submit API gave an error like this

{
  "transaction_identifier": {
    "hash": "1208160fe3caf2b9fe6a5e9cd0d61f2b6820a63ffffff29330d7c2450b9b639e"
  },
  "metadata": {
    "operations": [
      {
        "amount": { "e8s": 75000 },
        "fee": { "e8s": 10000 },
        "from": "a08f87a4699df926c0de647a791b9c4e8a3928e33db81ba4b92d844c7f77d757",
        "response": {
          "code": 700,
          "details": {
            "error_message": "Error submitting transaction TransactionIdentifier { hash: \"1208160fe3caf2b9fe6a5e9cd0d61f2b6820a63ffffff29330d7c2450b9b639e\" }: While parsing the read state response: deserializing request statuses failed: Other(\"missing field `status`\")."
          },
          "message": "Internal server error",
          "retriable": false
        },
        "status": "FAILED",
        "to": "f0d6ecc4116e9542be25f399a08a22d62584e344cd1ea5344caac93f622beb6f",
        "transaction_identifier": {
          "hash": "1208160fe3caf2b9fe6a5e9cd0d61f2b6820a63ffffff29330d7c2450b9b639e"
        },
        "type": "TRANSACTION"
      }
    ]
  }
}

I would like to know what is the correct way to create a transaction from a subaccount, an example would be better
THANKS FOR THE HELP

Hi @kevin61011 ,

There are two different Rosetta versions:
ICP Rosetta which allows you to communicate with the ICP ledger
ICRC Rosetta which allows you to communicate with ICRC-1 Ledgers (ckBTC,ckETH,…)

For ICP Rosetta, there are no Subaccounts supported. You can derive an accountidentifier from your public key as described here.

For ICRC Rosetta you can use Subaccounts. You can find an example for this here.

Thanks, I’ll look into it!