soroban-cli
soroban-cli copied to clipboard
Add a `stellar contract info wasm-hash` command
What problem does your feature solve?
It would be handy for devs to be able to retrieve the wasm hash of a contract.
What would you like to see?
$ stellar contract info wasm-hash --network testnet --contract-id CDSJWGUPY2HFHYNLT3EZX7YGJ4X7YMWPQWHHGNKB6IVH6WRXAJFI7627
283f8e42a3585aa3a511c06c7d09a94d66762773cdf493cc4afc455d7b68adcf
What alternatives are there?
There are some other ways to get the Wasm hash that a contract ID is deployed with.
Using RPC + XDR
The RPC and any XDR decode can be used to manually retrieve the details, however this is not convenient for a developer needing the value at the command line. For example:
curl -sSLX POST https://soroban-testnet.stellar.org \
--header 'content-type: application/json' \
--data '{
"jsonrpc": "2.0",
"id": 1,
"method": "getLedgerEntries",
"params": {
"keys": ["'"$(echo '{
"contract_data": {
"contract": "CDSJWGUPY2HFHYNLT3EZX7YGJ4X7YMWPQWHHGNKB6IVH6WRXAJFI7627",
"key": "ledger_key_contract_instance",
"durability": "persistent"
}}' | stellar xdr encode --type LedgerKey)"'"]
}
}' | jq -r '.result.entries[0].xdr' | \
stellar xdr decode --type LedgerEntryData | \
jq -r '.contract_data.val.contract_instance.executable.wasm'
283f8e42a3585aa3a511c06c7d09a94d66762773cdf493cc4afc455d7b68adcf
Using log output
I'm pretty sure there are some commands in the cli where the wasm hash is outputted when retrieving the wasm for other purposes. I can't remember which one it is at the moment, but these commands exist for other purposes an the hash is only outputted in informational stderr logs, which is not accessible for scripting.
I advocate for hash or wasm-hash. When I read the title I thought it was going to be about the spec or wasm related info.
Good point. wasm-hash would remove the most ambiguity and be consistent with option names --wasm-hash that are littered throughout the cli. I've updated the title to match.
@fnando says he will talk to @leighmcculloch about the usefulness of this command