Icrc1 block index

Hi dfinity team, I build a canister with icrc1 wasm and candid file, but there is no tip_of_chain interface in the icrc1 ledger(I want to query the newest block).
So how can I add the tip_of_chain to my own ledger? Should I copy the ICP-related “tip_of_chain” ledger code into the icrc1 ledger?

The ICRC Ledger has a get_data_certificate endpoint that can be used to achieve the same result. You can see an example of usage of get_data_certificate in the function sync_from_the_tip that we use in Rosetta. Eventually we will add an utility function to the ICRC Agent that exacts the hash and index of the last block from the get_data_certificate endpoint.

Hi mariop, I check this page again, but there is no “get_data_certificate” interface in the icrc1.did(Internet Computer Loading,
https://raw.githubusercontent.com/dfinity/ic/1612a202d030faa496e1694eed98be4179fca856/rs/rosetta-api/icrc1/ledger/icrc1.did).
And in your example code, the ICRC1 agent has a query method for “get_data_certificate” interface, so maybe the icrc1.did not update?

That’s because at that commit the interface of the canister was split in two files, the icrc1 standard one and the one with non-standard endpoints. Since then, we consolidated the candid files into one.

Off the top of my head… you can call get transactions with 0 and length of 1. In the return data is a field with the number of transactions.

I know what you say about it, but the interface I want to call is, 1.no input parameters, 2.return the latest block index. (such as “tip_of_chain”)

1 Like

Sorry again, I downloaded the ledger.did you post above, and add the wasm(curl -o icrc1-ledger.wasm.gz “https://download.dfinity.systems/ic/1612a202d030faa496e1694eed98be4179fca856/canisters/ic-icrc1-ledger.wasm.gz
) to my project, here is my generated did Canister: ozcip-uyaaa-aaaah-adkfa-cai - IC Dashboard, but still no get_data_certificate() interface.
I don’t know whether I made the wrong step.

I think what’s happening is that 1612a20 is old and doesn’t have the full interface yet attached. The endpoint is there but you cannot see it from the canister UI. I tried the more recent version 0213856 and it does have the endpoint also in the canister UI.

The artifacts I used are:

$ curl -f -o icrc1-ledger.wasm.gz "https://download.dfinity.systems/ic/02138563741c87cefed2b223e31f25b59623307a/canisters/ic-icrc1-ledger.wasm.gz"
$ curl -f -o icrc1-ledger.did "https://raw.githubusercontent.com/dfinity/ic/02138563741c87cefed2b223e31f25b59623307a/rs/rosetta-api/icrc1/ledger/ledger.did"
1 Like

Thanks, it works! And I hope that the Dfinity Team can update the newest download page.

1 Like

Hi, I’m trying to setup rosetta with my custom token and am following this guide here.
I’m pulling the latest wasm and did from here

"candid": "https://raw.githubusercontent.com/dfinity/ic/3bcccef07408921fe849c92dd2437adc157ef9c3/rs/rosetta-api/icrc1/ledger/ledger.did",
"wasm": "https://download.dfinity.systems/ic/3bcccef07408921fe849c92dd2437adc157ef9c3/canisters/ic-icrc1-ledger.wasm.gz"

When I start the docker with command described in the guide, I get the error that the method tip_of_chain_pb is missing.

09:16:46.031664 INFO [main] ic_rosetta_api - Starting ic-rosetta-api, pkg_version: 1.8.0
09:16:46.032495 INFO [main] ic_rosetta_api - Listening on 0.0.0.0:8080
09:16:46.032621 WARN [main] ic_rosetta_api - Data certificate will not be verified due to missing root key
09:16:46.041682 WARN [main] ic_ledger_canister_blocks_synchronizer::canister_access - Fetching the root key from the replica because it was not set
09:16:47.323596 WARN [main] ic_rosetta_api::ledger_client - Symbol endpoint not present in the ledger canister. Couldn't verify token symbol.
09:16:47.388245 INFO [main] ic_ledger_canister_blocks_synchronizer::ledger_blocks_sync - Loading blocks from store
09:16:47.388646 INFO [main] ic_ledger_canister_blocks_synchronizer::ledger_blocks_sync - Ledger client is up. Loaded 0 blocks from store. First block at None, last at None
09:16:47.389916 INFO [main] ic_rosetta_api - Network id: NetworkIdentifier { blockchain: "Internet Computer", network: "0000000001800bab0101", sub_network_identifier: None }
09:16:47.394654 INFO [main] ic_rosetta_api::rosetta_server - Starting Rosetta API server
09:16:47.632645 ERROR [main] ic_rosetta_api::rosetta_server - Error in syncing blocks: InternalError(false, Details { error_message: Some("In tip: The Replica returned an error: code 3, message: \"IC0302: Canister 6uad6-fqaaa-aaaam-abovq-cai has no query method 'tip_of_chain_pb'\""), extra_fields: {} })

Am I using the wrong docker rosetta version or setting something up wrongly?

Hi dustin, it’s not docker version problem, the reason is that the “tip_of_chain_pb” interface hasn’t been updated on icrc1 ledger, now we can only query “get_data_certificate” interface to obtain a complicated struct and decode related transaction hash.

hi @cymqqqq, thanks for the response. Then my main question is how can I use the docker image of rosetta that dfinity provides (or any other) to have the rosetta-api running for my token?

It seems like the page is not up-to-date, maybe the dfinity team need to add some additional parameters to the docker startup operation.

@mariop Do you know more about this or could tag someone from the team who could help?