# Call

If you run `pop call` without a subcommand, Pop CLI uses `pop call chain` unless it detects a contract project in the current directory. If chain support is disabled and no contract project is detected, it returns an error.

### What Can You Do?

The `pop call chain` command supports three types of operations:

#### 1. Execute Extrinsics

Submit transactions to the chain by calling dispatchable functions. These require signing and will modify chain state.

#### 2. Query Storage

Read storage items from the chain's state. Storage queries don't require signing and can read:

* **Plain storage values** (e.g., System::Number - the current block number)
* **Storage maps** (e.g., System::Account - account information by address)

#### 3. Read Constants

Access constant values defined in the runtime metadata (e.g., System::Version, System::BlockHashCount).

### Interactive Guidance (Recommended)

Interact with a chain **using** Pop CLI's interactive guidance by simply entering:

```shell
pop call chain
```

First, you will be prompted to select which chain you want to interact with from a list of available chains. You can type to filter the list and quickly find your desired chain. If you want to connect to a custom RPC endpoint, select the **"Custom"** option, which allows you to manually type the chain URL.

After selecting your chain, you will be prompted to select a pallet, then choose what you want to do with that pallet:

* **Execute an extrinsic** (function that modifies state, e.g. balance transfer)
* **Query storage**
* **Read constants**

After making your selection, you'll be guided through providing any required arguments and (for extrinsics) the account to sign the transaction.

### Manual (non-interactive)

If you prefer not to use interactive prompts, you can call the chain by specifying all the required arguments directly:

#### Executing an Extrinsic

You can execute an extrinsic by specifying the pallet and function (dispatchable function name) and any arguments.

> \[!TIP] If you receive "Pallet not found" or "Function not found" errors, double-check the case of your pallet and function names. Common examples: use "Balances" (not "balances"), "transfer\_keep\_alive" (not "transferKeepAlive").

```shell
pop call chain --pallet System --function remark --args "0x11" --url ws://localhost:9944 --suri //Alice --sudo
```

To submit directly without the final "submit extrinsic?" prompt, add `--execute`:

```shell
pop call chain --pallet System --function remark --args "0x11" --url ws://localhost:9944 --suri //Alice --execute
```

#### Querying Storage

You can query storage items by specifying the pallet and function (storage item name). Storage queries return the current value immediately without requiring transaction signing. You do not need `--skip-confirm` for read-only calls. If the storage item is a map, provide a key with `--args`. In interactive mode, leave the key blank to query all entries. For composite map keys, you can pass tuple-style arguments (for example `(ASSET_ID,ACCOUNT)`), or provide each key part in order.

```shell
pop call chain --pallet Sudo --function Key --url wss://pas-rpc.stakeworld.io -y
```

```shell
pop call chain --pallet System --function Account --args 0xb815821c5b300d1667d5fc081c06cc4b6addffb90464d68d871ee363b01a127c --url wss://pas-rpc.stakeworld.io -y
```

```shell
# Composite-key storage example (tuple-style key)
pop call chain --pallet Assets --function Account --args '(1984,5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY)' --url ws://localhost:9944/
```

#### Reading Constants

Query constant values from the runtime. Constants are read directly from metadata and don't require signing or keys.

```shell
pop call chain --pallet System --function Version --url wss://pas-rpc.stakeworld.io -y
```

```shell
pop call chain --pallet System --function BlockHashCount --url wss://pas-rpc.stakeworld.io -y
```

### Additional Options

**When do you need signing?**

You need a signer for extrinsics only. Storage queries and constants never require signing.

#### View Metadata

Use `--metadata` to inspect runtime metadata. If you omit `--pallet`, Pop CLI lists all pallets. If you include `--pallet`, it lists calls, storage, and constants for that pallet.

`--metadata` conflicts with `--function`, `--args`, `--suri`, `--use-wallet`, `--call`, and `--sudo`.

```shell
pop call chain --metadata --url ws://localhost:9944/
```

```shell
pop call chain --pallet System --metadata --url ws://localhost:9944/
```

#### Sudo Calls

To dispatch a call with Root origin when the chain's runtime includes `pallet-sudo`, you can wrap the call in a `sudo.sudo()` call by using the `--sudo` flag:

```shell
pop call chain --pallet System --function remark --args "0x11" --url ws://localhost:9944 --suri //Alice --sudo
```

#### Using Wallet for Signing

You can use a browser extension wallet to sign extrinsics instead of providing a secret URI:

```shell
pop call chain --pallet System --function remark --args "0x11" --url ws://localhost:9944/ --use-wallet
```

Or use the shorthand `-w`:

```shell
pop call chain --pallet System --function remark --args "0x11" --url ws://localhost:9944/ -w
```

#### Direct Call Data Submission

If you already have the SCALE-encoded call data and want to directly submit the extrinsic:

```shell
pop call chain --call 0x00000411 --url ws://localhost:9944/ --suri //Alice
```

`--call` conflicts with `--pallet`, `--function`, and `--args`.

```
┌   Pop CLI : Call a chain
│
⚙  Encoded call data: 0x00000411
│  
◇  Do you want to submit the extrinsic?
│  Yes 
│
◇  Extrinsic submitted successfully with hash: "0x60b10fa42fa7bb9e36460d199cef55b28b41dae3f9bb3326fc0e584009ce305b"
│
└  Call complete.
```

#### Skip Confirmation

Use the `--skip-confirm` or `-y` flag to automatically submit extrinsics without prompting for confirmation. This also prevents the prompt to perform another call:

```shell
pop call chain --pallet System --function remark --args "0x11" --url ws://localhost:9944/ --suri //Alice -y
```

If you use `--skip-confirm` with an extrinsic, you must provide a signer with `--suri` or `--use-wallet`.

This is particularly useful for scripting and automation.

If you only want to skip the submit confirmation (but keep other interactive prompts), use `--execute`.

#### Exit Codes for Automation

`pop call chain` exits with a non-zero code when a call fails (for example RPC errors, invalid pallet/function names, or failed submission). This makes shell scripting and CI checks reliable.

### Upcoming: JSON mode (`#993`, pending merge)

`pop call chain` is planned to support global `--json` with structured envelopes once [`#993`](https://github.com/r0gue-io/pop-cli/pull/993) merges.

Planned usage:

```shell
pop --json call chain --pallet System --function remark --args 0x11 --url ws://localhost:9944 --suri //Alice --execute
```

Planned behavior:

* Interactive prompts are disabled in JSON mode; required inputs must be passed via flags.
* Errors are returned with typed codes for automation (`INVALID_INPUT`, `PROMPT_REQUIRED`, `NETWORK_ERROR`, `INTERNAL`).

#### Quick URL Entry

When prompted for a chain, you can select "Custom" to quickly type the chain URL manually, accelerating the process when you already know the endpoint.

### Examples

#### Example 1: Query Current Block Number

```shell
pop call chain --pallet System --function Number --url ws://localhost:9944/
```

#### Example 2: Check an Account Balance

```shell
pop call chain --pallet System --function Account --args "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY" --url ws://localhost:9944/
```

#### Example 3: Read Runtime Version

```shell
pop call chain --pallet System --function Version --url ws://localhost:9944/
```

#### Example 4: Transfer with Wallet

```shell
pop call chain --pallet Balances --function transfer_keep_alive --args "5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty" "1000000000000" --url wss://rpc.polkadot.io --use-wallet
```

#### Example 5: Sudo Call with Auto-confirm

```shell
pop call chain --pallet System --function set_code --args "./runtime.wasm" --url ws://localhost:9944/ --suri //Alice --sudo -y
```

**Need help?**

Ask on [Polkadot Stack Exchange](https://polkadot.stackexchange.com/) (tag it [`pop`](https://substrate.stackexchange.com/tags/pop/info)) or drop by [our Telegram](https://t.me/onpopio). We're here to help!
