Skip to content

jzu/bac

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 

Repository files navigation

bac - Basic Avalanche CLI

bac acts as a Unix command-line interface wrapper around the Avalanche JSON API, making it easier to call simple methods.

-f formats the output using jq.
-n does nothing but display the Curl command.
-h gives help.
Arguments are key:value pairs (quotes unnecessary), pairs being separated by spaces.
Endpoint is inferred from the service part of the method.

Usage example

bac -f avm.getBalance address:X-avax1tmnpf87ph0pap4p507zfr0zesafnj5qh0sdkjc assetID:AVAX

Providing an incomplete method name (i.e. without . or _) has it grepped in [/usr/local/etc/]bac.sigs and matching method signatures are displayed. The file has been generated by scraping the documentation pages, some basic text processing, and manual editing. Methods suffixed with ! are deprecated. Arguments suffixed with ° are optional. Example:

$ bac blockchain
platform.createBlockchain! : subnetID, vmID, name, genesisData, encoding°, from[]°, changeAddr°, username, password
platform.getBlockchains!
platform.getBlockchainStatus : blockchainID

Advanced Usage

Ok, this is the Basic Avalanche CLI, but you can do whatever you want, even with the avax API now (beta). You can also use avalanche-cli. You may find it better suited for complex requests.

Objects and Arrays

You write objects pretty much as you would in JSON, only simpler:

key1:{key2a:value2a key2b:{key3a:value3a key3b:value3b}}

Same for arrays:

key1:[value1a value1b]

Installation

The script works in any directory by calling ./bac … provided it has execution rights (chmod 755 bac if it's not the case), but you can install it system-wide:

sudo install -m 755 bac /usr/local/bin
sudo install -m 644 bac.sigs /usr/local/etc

There are no prerequisites if you only need raw outputs. The -f (format) option wants jq, which you can install using apt install jq.

Limitations

All services are (supposed to be) supported, except

  • the C-chain (not fully tested, some methods do work)
  • there's always one more bug (Lubarsky's Law of Cybernetic Entomology)

… for now.

gensigs.pl never really worked and has been discarded.
The -n option forgets the simple quotes.
The EVM API seems incomplete.
The avax RPC endpoints are unmanageable in an automatic way: see https://docs.avax.network/apis/avalanchego/apis/c-chain.
You shouldn't try to understand the PARAMS sed regexps, unless you're into Malbolge.
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. (J. Zawinski)

About

Basic Avalanche CLI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages