How to retrieve contract state from node-sdk?

Hello! I’m trying to upgrade contract version from 0 to 1.
At contract v0, I was able to get the model using getInstanceInfo(), but it is no longer available at v1.
github - concordium-node-sdk-js

Maybe I should use the view function, but how can I use it with nodejs(actually client for browser)?

And let me ask another related question.

Command concordium-client contract show also no longer displays state.
Is there any command to retrieve the contract state?


We have the same issue, we also need to inspect the state and use the information from the state in our contract.

1 Like

Hello everyone

I passed on your questions for the core team. As soon as they got some answers, I will get back to you.

Concordium Tech Support

Hi :wave:

Yes, @newsnow, you should write view functions to access the state that you need. And then use the InvokeContract endpoint for accessing the result. The NodeJS SDK does not support the InvokeContract endpoint yet, but it is in the works: Add new events and entrypoint related to V1 smart contracts · Issue #31 · Concordium/concordium-node-sdk-js · GitHub. (Some of our other SDKs already have this endpoint, e.g. GitHub - Concordium/concordium-rust-sdk).

contract show does not display the state for v1 contracts because the state can be very large and contract show is meant for getting an overview of the contract instance. Instead, you should use contract invoke and view functions.
Also, note that you can use the parameter to query for specific info from a view function. For example, you could pass in an account address to get a list of all the NFTs owned by that address.

Best regards,


OK, I understand. Thanks for answering my question!

Let me confirm one thing.

When you use view function and InvokeContract of gRPC endpoint, that does not cost any energy, right?

so when you call view function via invoke_contract() in the contract to communicate with other contracts, does that consume any energy?

InvokeContract does not cost any CCD. It still keeps track of how much energy was used, but only for informational purposes (and you can use it to limit the amount of time the node spends answering a query, if you want).

Even if InvokeContract involves communication with other contracts that is purely local on your node, it is not recorded on the blockchain, and thus does not cost any CCD.

Only transactions cost CCD, and those must be submitted via SubmitTransaction.

1 Like

Thank you for your explanation.
I’ll keep looking into version 1!

1 Like