Skip to main content

query

Usage: chr query [OPTIONS] QUERYNAME [ARGS]...

Make a query towards a running node

╭─ Configuration Properties ───────────────────────────────────────────────────────────────────────────────────────────╮
│ -cfg, --config=CONFIG Alternate path for client configuration file
│ -s, --settings=SETTINGS Alternate path for project settings file
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Node ───────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ Make query/tx towards a test node
│ │
│ -brid, --blockchain-rid=TEXT Target Blockchain RID │
│ --cid=INT Target Blockchain IID (default: 0)
│ --api-url=TEXT Target api url (default: http://localhost:7740)
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Deployment ─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ Make query towards a configured deployment │
│ │
│ -d, --network=TEXT Specify which deployment target to use │
│* -bc, --blockchain=TEXT Name of blockchain in deployment configuration │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ -h, --help Show this message and exit
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Arguments ──────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ QUERYNAME name of the query to make. │
│ ARGS arguments to pass to the query. The dict is passed either as key-value pairs or as a single dict element.│
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

You can use the query command (chr query) to test and interact with a chain that's either local or deployed without using a client. You can set a path for the project config file (chromia.yml) or specify a different file using --settings. In addition to that, you can change between a local and deployed chain target with the --deployment and --local flags. The flag is --local by default.

Node

When you start a node, you can see the Blockchain RID as the standard output. An example would look like this: Blockchain RID: FC17B67D66F6F35A5D8B75ED3F83AE222FB8C8FCA241624F06285150F10C6BAC. If you run the node on a different URL than the default http://localhost:7740, you can use the --api-url in the chromia.yml to specify it.

  • To run the query hello_world specified in the main.rell file.
chr query --blockchain-rid <BlockchainRID> hello_world
  • If the query has an argument called foo, then the query would look like the following for the value bar.
chr query --blockchain-rid <BlockchainRID> hello_world "{foo=bar}"
  • If you want to pass a dictionary as an argument, you have to separate the argument with -- to avoid = incorrect parsing.
chr query hello_world -- {key1=value1, key2=value2}

Deployed

Towards a deployed chain, you can use the same commands as in a local environment, but you need to add a --name (deployment target) and --blockchain (name of the chain to query) instead of the --blockchain-rid.

chr query --deployment --name testnet --blockchain hello hello_world