injectived, the command-line interface that connects to Injective. You can use injectived to interact with the Injective blockchain by uploading smart contracts, querying data, managing staking activities, working with governance proposals, and more.
Prerequisites
Ensuring injectived is installed
See Install injectived for more information. If you have installedinjectived successfully, you should be able to run the following command:
Using Dockerized CLI
In case when running from Docker, you have to mount the home dir to the container.- docker runs the image
injectivelabs/injective-core:v1.14.1 injectivedis the command to run the CLI from within the containerkeys addis the command to add a keymy_keyis the name of the key--home /root/.injectiveis the home directory for CLI inside the container-v ~/.injective:/root/.injectivesimply mounts the host~/.injectivedir to the container’s/root/.injectivedir.
/root/.injective/keyring-file dir, which is the same as your host ~/.injective/keyring-file dir.
You can list all the keys by running:
Using the RPC endpoint
Before you can access the Injective blockchain, you need to have a node running. You can either run your own full node or connect to someone else’s. To query the state and send transactions, you must connect to a node, which is the access point to the entire network of peer connections. You can either run your own full node or connect to someone else’s. Running own node is for advanced users only. For most users, it is recommended to connect to a public node. To set the RPC endpoint, you can use the following command:For testnet only, you can use:
https://k8s.testnet.tm.injective.network:443 (chain-id injective-888)General help
For more general information aboutinjectived, run:
injectived command, append the -h or --help flag after the command. For example:
Configuring injectived client
To configure more options of injectived, edit the config.toml file in the ~/.injective/config/ directory. Keyring file is located in ~/.injective/keyring-file directory when keyring-backend is set to file. It’s possible to set keyring-backend to test or os as well. In case for the test, it will be also stored as file ~/.injective/keyring-test but not password-protected.
All options in the file can be set using the CLI: injectived config set client <option> <value>.
Generate, Sign, and Broadcast a Transaction
Running the following command sends INJ tokens from the sender’s account to the recipient’s account.1000inj is the amount of INJ tokens to send, where 1 INJ = 10^18 inj, so 1000inj is a really small amount.
- Generates a transaction with one
Msg(x/bank’sMsgSend), and print the generated transaction to the console. - Ask the user for confirmation to send the transaction from the
$MY_WALLETaccount. - Fetch
$MY_WALLETfrom the keyring. This is possible because we have set up the CLI’s keyring in a previous step. - Sign the generated transaction with the keyring’s account.
- Broadcast the signed transaction to the network. This is possible because the CLI connects to the public Injective node’s RPC endpoint.
(Only) Generating a Transaction
Generating a transaction can simply be done by appending the--generate-only flag on any tx command, e.g.,
> unsigned_tx.json to the above command.
Signing a pre-generated Transaction
Signing a transaction using the CLI requires the unsigned transaction to be saved in a file. Let’s assume the unsigned transaction is in a file calledunsigned_tx.json in the current directory (see previous paragraph on how to do that). Then, simply run the following command:
SIGN_MODE_DIRECT with MY_WALLET’s key, which we already set up in the keyring. The signed transaction will be output as JSON to the console, and, as above, we can save it to a file by appending > signed_tx.json to the commandline.
tx sign command:
--sign-mode: you may useamino-jsonto sign the transaction usingSIGN_MODE_LEGACY_AMINO_JSON,--offline: sign in offline mode. This means that thetx signcommand doesn’t connect to the node to retrieve the signer’s account number and sequence, both needed for signing. In this case, you must manually supply the--account-numberand--sequenceflags. This is useful for offline signing, i.e., signing in a secure environment which doesn’t have access to the internet.
Signing with multiple signers (Multi Sig)
Signing with multiple signers is done with thetx multi-sign command. This command assumes that all signers use SIGN_MODE_LEGACY_AMINO_JSON. The flow is similar to the tx sign command flow, but instead of signing an unsigned transaction file, each signer signs the file signed by previous signer(s). The tx multi-sign command will append signatures to the existing transactions. It is important that signers sign the transaction in the same order as given by the transaction, which is retrievable using the GetSigners() method.
For example, starting with the unsigned_tx.json, and assuming the transaction has 4 signers, we would run:
Broadcasting a Transaction
Broadcasting a transaction is done using the following command:--broadcast-mode flag to specify which response to receive from the node:
block: the CLI waits for the tx to be included in a block.sync: the CLI waits for a CheckTx execution response only, query transaction result manually to ensure it was included.async: the CLI returns immediately (transaction might fail) - DO NOT USE.
