Skip to content

Add a stellar contract info wasm-hash command #1877

@leighmcculloch

Description

@leighmcculloch

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions