How does dfx call canister_info and canister_status?

In the documentation I can see the system API calls for canister_info and canister_status which can be called from a canister, but not from externally. How does dfx obtain this information? I can’t find anything in the gateway HTTP API spec regarding info or status.

For canister_info, dfx reads the state tree. This is a nice place to read the code.

For canister_status dfx simply calls the management canister. From the spec:

This method can be called by canisters as well as by external users via ingress messages.

1 Like

Great. Thank you very much.

Do you also happen to have a js example that reads from the system state tree?

Ok, got it. I got initially confused by the signature here:

ic0.canister_status : () → i32

which has no arguments and made think that it wasn’t possible to call externally because there is no way to specify which canister to query about. But this is only the system API for wasm code. The management canister service looks like this

canister_status : (canister_status_args) -> (canister_status_result);

It’s clear now. Thank you.

I found agent-js’ readState here, and there is an example how it’s used here, but I don’t really know JS so that’s just the result of some educated guessing

1 Like