Skip to main content

Using the NEAR CLI

Calimero works seamlessly with all NEAR tooling, including the NEAR CLI. To get started, follow these steps:

Installation

Install the NEAR CLI by running the following command:

npm install -g near-cli

To verify the installation and check the current version, use the following command:

near --version

You can find detailed documentation on using the NEAR CLI with Calimero Private Shards on the official NEAR docs: https://docs.near.org/tools/near-cli.

Requirements

To use the NEAR CLI with Calimero, you need to meet the following requirements:

  • Generate an authentication token on the Security page inside the Calimero Console.
  • Set the custom RPC endpoint for the CLI tool to use from your Dashboard.
  • Set the API token for the CLI to use.

Set up the NEAR CLI to access the Shard via CLI

To interact with the Calimero shard using near-cli, you need to set the token value using the near set-api-key command. Run the following command, replacing <AUTH_TOKEN> with your token value:

near set-api-key https://rpc.testnet.near.org <AUTH_TOKEN>

Please note that the value https://rpc.testnet.near.org is currently ignored by the CLI. However, this issue will be fixed and released in the next version of the CLI.

Verify the NEAR state

To verify the setup, first set your variables:

export SHARD_RPC_URL="<YOUR_SHARD_RPC_URL>"
export SHARD_ID="<YOUR_SHARD_ID>"

Replace <SHARD_ID> with your shard name. Replace <SHARD_RPC_URL> with the URL of the shard's RPC node.

After exporting these parameters, you can use them in the near state command as follows:

near state $SHARD_ID.calimero.testnet --nodeUrl $SHARD_RPC_URL --networkId $SHARD_ID-calimero-testnet

Here is an example:

near state demo.calimero.testnet --nodeUrl https://api.calimero.network/api/v1/shards/demo-calimero-testnet/neard-rpc/ --networkId demo-calimero-testnet

Interacting with the RPC Server URL

The RPC server allows direct communication with the NEAR network. By default, the NEAR CLI sends requests to the testnet at https://rpc.testnet.near.org.

To interact with the Calimero shard, you need to use the URL of the shard's RPC node: https://api.calimero.network/api/v1/shards/demo-calimero-testnet/neard-rpc/.

Options

You can run near --help to see all available options.

Alias

To simplify the usage of the NEAR CLI with Calimero, you can define a shell alias. Here's an example for defining an alias in zsh:

alias calimero='calimero_wrapper() {
local command="$1";
local max_gas="300000000000000";
local node_url="<RPC_URL>";
local network_id="<SHARD_ID>";
local args=();

if [[ "$command" == "call" ]]; then
args=("$@");
near "${args[@]}" --gas $max_gas --nodeUrl "$node_url" --networkId "$network_id";
else
args=("$@");
near "${args[@]}" --nodeUrl "$node_url" --networkId "$network_id";
fi
}; calimero_wrapper'

Using the values from this article:

alias calimero='calimero_wrapper() {
local command="$1";
local max_gas="300000000000000";
local node_url="https://api.calimero.network/api/v1/shards/demo-calimero-testnet/neard-rpc/";
local network_id="demo-calimero-testnet";
local args=();

if [[ "$command" == "call" ]]; then
args=("$@");
near "${args[@]}" --gas $max_gas --nodeUrl "$node_url" --networkId "$network_id";
else
args=("$@");
near "${args[@]}" --nodeUrl "$node_url" --networkId "$network_id";
fi
}; calimero_wrapper'

With the alias defined, you can now use the NEAR CLI with Calimero. For example:

calimero state demo.calimero.testnet