# Tx Api

## RPC API Reference

Pando offers two sets of RPC APIs. The rationale of this division is to separate the public interface accessible to all users and personal interface that manages a specific user's private wallet.

The Pando **APIs** is provided by the Pando Node. It is the RPC interface via which a user can interact with the Pando Node directly. As described in the [setup guide](https://theta.readme.io/docs/setup), the Pando Node can be launched with the following command. By default the Pando node runs its RPC server at port 16888.

Pando `start --config=<path/to/config/folder>`

The **PandoCli APIs** is provided by the PandoCli Daemon. It allows a user to interact with his/her personal Pando Wallet through RPC calls. The wallet can manange multiple accounts simultaneously. The encrypted private keys of the accounts are stored under \~/.Pandocli/keys/encrypted/ by default. The RPC APIs supports account creation, lock/unlock, and sending Pando/PTX. The PandoCli Daemon can be run by the following command. If the port parameter is not specified, by default it runs at port 16889. Note that part of the PandoCli Daemon's functionality depends on the Pando Node. Hence we need to have the Pando Node running when we launch the PandoCli Daemon.

Pando`cli daemon start --port=`

In the examples below, we assume the reader has followed the [setup guide](https://theta.readme.io/docs/setup) to launch **both** the Pando Node and the PandoCli Daemon on the local machine at port 16888 and 16889 respectively.

We have also implemented a JavaScript SDK Pando.js for ease of DApp development. Please refer to [here for more details](https://docs.thetatoken.org/docs/theta-js-sdk).

[Suggest Edits](https://docs.thetatoken.org/edit/rpc-api-reference)

## Pando APIs

## Query APIs

### **GetVersion**

This API returns the version of the blockchain software.

**RPC Method:** Pando.GetVersion

**Returns**

* version: the version number
* git\_hash: the git commit hash of the code base
* timestamp: the build timestamp

**Example**

Shell

```shell
// Request
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"Pando.GetVersion","params":[],"id":1}' http://localhost:16888/rpc

// Result
{
	"jsonrpc": "2.0",
	"id": 1,
	"result": {
		"version": "1.0",
		"git_hash": "9d7669a735063a283ae8b6f0826183e3830c00a5",
		"timestamp": "Tue Feb 19 23:31:32 UTC 2019"
	}
}
```

### GetAccount

This API returns the details of the account being queried in json format.

**RPC Method:** Pando.GetAccount

**Query Parameters**<br>

* address: the address of the account

**Returns**

* code: the hash of the smart contract bytecode (for smart contract accounts)
* coins: the native token balance
* reserved\_funds: fund reserved for micropayment through the off-chain resource-oriented payment pool
* root: the root hash of the data Merkle-Patricia trie (for smart contract accounts)
* sequence: the current sequence number of the account

**Example**

Shell

```shell
// Request
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"Pando.GetAccount","params":[{"address":"0x2E833968E5bB786Ae419c4d13189fB081Cc43bab"}],"id":1}' http://localhost:16888/rpc

// Result
{
	"jsonrpc": "2.0",
	"id": 1,
	"result": {
		"sequence": "1",
		"coins": {
			"PandoWei": "994999990000000000000000000",
			"PTXWei": "4999999979999999000000000000"
		},
		"reserved_funds": [],
		"last_updated_block_height": "0",
		"root": "0x0000000000000000000000000000000000000000000000000000000000000000",
		"code": "0x0000000000000000000000000000000000000000000000000000000000000000"
	}
}
```

### GetBlock

This API returns the block being queried in json format.

**RPC Method:** Pando.GetBlock

**Query Parameters**<br>

* hash: the block hash
* include\_eth\_tx\_hashes: whether to include the ETH tx hash of the smart contract transactions in the response.

**Returns**

* chain\_id: ID of the chain
* epoch: epoch of the block
* height: height of the block
* parent: hash of the parent block
* transactions\_hash: root hash of the transaction Merkle-Patricia trie
* state\_hash: root hash of the state Merkle-Patricia trie
* timestamp: timestamp when the block was proposed
* proposer: address of the proposer validator
* children: children blocks
* hash: the block hash
* transactions: json representation of the transactions contained in the block
* raw: transaction details
* type: type of the transaction (see the Transaction Types note below)
* hash: hash of the transaction
* status: status of the block (see the Block Status note below)

**Transaction Types**

Text

```
0: coinbase transaction, for validator/guardian reward
1: slash transaction, for slashing malicious actors
2: send transaction, for sending tokens among accounts
3: reserve fund transaction, for off-chain micropayment
4: release fund transaction, for off-chain micropayment
5: service payment transaction, for off-chain micropayment
6: split rule transaction, for the "split rule" special smart contract
7: smart contract transaction, for general purpose smart contract
8: deposit stake transaction, for depositing stake to validators/guardians
9: withdraw stake transaction, for withdrawing stake from validators/guardians
```

**Block Status**

Text

```
0: pending 
1: valid
2: invalid
3: committed
4: directly finalized
5: indirectly finalized
6: trusted (the first block in a verified snapshot is marked as trusted)
```

A block and all the transactions included in the block are considered Finalized by the validators if the block status is either 4, 5, or 6

Text

```
Block status transitions:

+-------+          +-------+                          +-------------------+
|Pending+---+------>Invalid|                    +----->IndirectlyFinalized|
+-------+   |      +-------+                    |     +-------------------+
            |                                   |
            |      +-----+        +---------+   |     +-----------------+
            +------>Valid+-------->Committed+---+----->DirectlyFinalized|
                   +-----+        +---------+         +-----------------+
```

**GetBlock Example**

In this example, we queried the block with hash `0x9f1e77b08c9fa8984096a735d0aae6b0e43aee297e42c54ce36334103ddd67a7`. This block contains two transactions. The first one is a "coinbase" transaction (type 0), and the second is a "send" transaction (type 2). In particular, in the "send" transaction, address `0x2e833968e5bb786ae419c4d13189fb081cc43bab` 20 PTX tokens to address `0x9f1233798e905e173560071255140b4a8abd3ec6`, which cost 1000000000000 PTXWei transaction fee.

Shell

```shell
// Request
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"Pando.GetBlock","params":[{"hash":"0x9f1e77b08c9fa8984096a735d0aae6b0e43aee297e42c54ce36334103ddd67a7", "include_eth_tx_hashes":false}],"id":1}' http://localhost:16888/rpc

// Result
{
	"jsonrpc": "2.0",
	"id": 1,
	"result": {
		"chain_id": "privatenet",
		"epoch": "5",
		"height": "3",
		"parent": "0x724b0f68d8e45f930b95bac224fa7d67eef243307b4e84f0f666198d1d70e9d7",
		"transactions_hash": "0x2bf2c62185fceed239a55bd27ada030cf75970f09122addb2e419e70cafebdf0",
		"state_hash": "0xd41742c2b0d70e3bac1d88b2af69a2491d8c65c650af6ec4d2b8873897f8becc",
		"timestamp": "1548102762",
		"proposer": "0x2e833968e5bb786ae419c4d13189fb081cc43bab",
		"children": ["0x21d3c2bb25d0c85a1f5c3ff81bc7eeae998bf98db1dba461fb3f69a434feb90c"],
		"status": 4,
		"hash": "0x9f1e77b08c9fa8984096a735d0aae6b0e43aee297e42c54ce36334103ddd67a7",
		"transactions": [{
			"raw": {
				"proposer": {
					"address": "0x2e833968e5bb786ae419c4d13189fb081cc43bab",
					"coins": {
						"PandoWei": "0",
						"PTXWei": "0"
					},
					"sequence": "0",
					"signature": "0x31af035f0dc47ded00eb5139fd5e4bb76f82e89e29adae60df1277a25b0c7b135b097502ff0aa66249a423d22f291804a9e178af59c24ccbf1af2f58b83964ef00"
				},
				"outputs": [{
					"address": "0x2e833968e5bb786ae419c4d13189fb081cc43bab",
					"coins": {
						"PandoWei": "0",
						"PTXWei": "0"
					}
				}],
				"block_height": "2"
			},
			"type": 0,
			"hash": "0x642f7d70680eefcc34f750cd6e03b57035f197baeabfa8e8420f55d994f5265f"
		}, {
			"raw": {
				"fee": {
					"PandoWei": "0",
					"PTXWei": "1000000000000"
				},
				"inputs": [{
					"address": "0x2e833968e5bb786ae419c4d13189fb081cc43bab",
					"coins": {
						"PandoWei": "10000000000000000000",
						"PTXWei": "20000001000000000000"
					},
					"sequence": "1",
					"signature": "0x2f8f17b13c07e57d4c5d2c89e87d9e608f0eff22ef1f96eed5647b063265450216ef4f7a8578bf702cf26db00fb2e758521873bb1b68528325c84b59a2debc7400"
				}],
				"outputs": [{
					"address": "0x9f1233798e905e173560071255140b4a8abd3ec6",
					"coins": {
						"PandoWei": "10000000000000000000",
						"PTXWei": "20000000000000000000"
					}
				}]
			},
			"type": 2,
			"hash": "0xf3cc94af7a1520b384999ad106ade9738b6cde66e2377ceab37067329d7173a0"
		}]
	}
}
```

### GetBlockByHeight

This API returns the finalized block given the height. If none of the blocks at the given height are finalized (either directly or indirectly), the API simply returns an empty result.

**RPC Method:** pando.GetBlockByHeight

**Query Parameters**

* height: the block height (need to pass in as a string instead of an integer)
* include\_eth\_tx\_hashes: whether to include the ETH tx hash of the smart contract transactions in the response.

**Returns**

Similar to the returns of the GetBlock API. Please see [above](https://theta.readme.io/docs/api-reference#getblock).

**Example**

In this example, we query the block at height 3. The result is similar to the result of the GetBlock API.

Shell

```shell
// Request
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"pando.GetBlockByHeight","params":[{"height":"3", "include_eth_tx_hashes":false}],"id":1}' http://localhost:16888/rpc

// Result
{
	"jsonrpc": "2.0",
	"id": 1,
	"result": {
		"chain_id": "privatenet",
		"epoch": "5",
		"height": "3",
		"parent": "0x724b0f68d8e45f930b95bac224fa7d67eef243307b4e84f0f666198d1d70e9d7",
		"transactions_hash": "0x2bf2c62185fceed239a55bd27ada030cf75970f09122addb2e419e70cafebdf0",
		"state_hash": "0xd41742c2b0d70e3bac1d88b2af69a2491d8c65c650af6ec4d2b8873897f8becc",
		"timestamp": "1548102762",
		"proposer": "0x2e833968e5bb786ae419c4d13189fb081cc43bab",
		"children": ["0x21d3c2bb25d0c85a1f5c3ff81bc7eeae998bf98db1dba461fb3f69a434feb90c"],
		"status": 4,
		"hash": "0x9f1e77b08c9fa8984096a735d0aae6b0e43aee297e42c54ce36334103ddd67a7",
		"transactions": [...]
	}
}
```

### GetTransaction

This API returns the transaction being queried in json format.

**RPC Method:** pando.GetTransaction

**Query** Parameters

* hash: the transaction hash\*

**Returns**

* block\_hash: hash of the block that contains the transaction
* block\_height: height of the block that contains the transaction
* status: status of the transaction
* hash: the hash of the transaction itself
* transaction: the details of the transaction

**GetTransaction Example 1**

In this example, the transaction being queried is a "send transaction" (i.e., type 2, see the [Transaction types](https://docs.thetatoken.org/docs/rpc-api-reference#transaction-types). In this transaction, address `0x2e833968e5bb786ae419c4d13189fb081cc43bab` 20 PTX tokens to address `0x9f1233798e905e173560071255140b4a8abd3ec6`, which cost 1000000000000 PTXWei transaction fee.

Shell

```shell
// Request
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"pando.GetTransaction","params":[{"hash":"0xf3cc94af7a1520b384999ad106ade9738b6cde66e2377ceab37067329d7173a0"}],"id":1}' http://localhost:16888/rpc

// Result
{
	"jsonrpc": "2.0",
	"id": 1,
	"result": {
		"block_hash": "0x9f1e77b08c9fa8984096a735d0aae6b0e43aee297e42c54ce36334103ddd67a7",
		"block_height": "3",
		"status": "finalized",
		"hash": "0xf3cc94af7a1520b384999ad106ade9738b6cde66e2377ceab37067329d7173a0",
		"transaction": {
			"fee": {
				"PandoWei": "0",
				"PTXWei": "1000000000000"
			},
			"inputs": [{
				"address": "0x2e833968e5bb786ae419c4d13189fb081cc43bab",
				"coins": {
					"PandoWei": "0",
					"PTXWei": "20000001000000000000"
				},
				"sequence": "1",
				"signature": "0x2f8f17b13c07e57d4c5d2c89e87d9e608f0eff22ef1f96eed5647b063265450216ef4f7a8578bf702cf26db00fb2e758521873bb1b68528325c84b59a2debc7400"
			}],
			"outputs": [{
				"address": "0x9f1233798e905e173560071255140b4a8abd3ec6",
				"coins": {
					"PandoWei": "0",
					"PTXWei": "20000000000000000000"
				}
			}]
		}
	}
}
```

**GetTransaction Example 2**

Smart contract transactions can be used to send PTX. For example, if you use Metamask to send PTX following the [steps here](https://medium.com/theta-network/theta-blockhain-now-accessible-through-metamask-plug-in-61b278633264), the PTX is sent through a smart contract transaction. In the transaction details, `transaction.from.coins.ptxwei` specifies the amount of PTX (in Wei) sent to the receiver address (see below for more details). Similar to ETH, some of the smart contract transactions just interact with a smart contract. They may not send any PTX to the contract. [This](https://explorer.thetatoken.org/txs/0xf4d520c9062dbf91c684a37ab4c5b08ae84e16111ea16759bb4fbf91e87738fa) is a smart contract transaction that did not send any PTX. On the other hand, [this](https://explorer.thetatoken.org/txs/0x6381651316d9f7b122b050c5d35a5f076a39c2aeb9507de42d9b71ea81290aa1) is a smart contract transaction with a non-zero PTX value. In this example, the transaction sends 702.8783 PTX to the receiver address `0x8366537d56cf2b86ca90e9dbc89450207a29f6e3`.

The following example show how to query the details of a "smart contract transaction" (i.e., type 7, see the [Transaction types](https://docs.thetatoken.org/docs/rpc-api-reference#transaction-types)). This type of transaction is similar to the Ethereum transaction:

* `transaction.from.address` is the sender address of the transaction
* `transaction.to.address` is the receiver address of the transaction. It can be a regular wallet, or a smart contract address
* `transaction.from.coins.ptxwei` is the amount of PTX (in unit wei, i.e. 10e-18 PTX) send to the receiver address. This corresponds to the `value` field of an [Ethereum transaction](https://ethereum.org/en/developers/docs/transactions/). In the example below, the sender is sending 250000000000000000000 PTXWei (i.e. 250 PTX) to the receiver address.
* `transaction.gas_limit` and `transaction.gas_price` are the the gas limit and gas price of the transaction, similar to the corresponding fields of an [Ethereum transaction](https://ethereum.org/en/developers/docs/transactions/).
* `transaction.data` is an optional field to include arbitrary data, similar to the `data` field of an [Ethereum transaction](https://ethereum.org/en/developers/docs/transactions/).
* `receipt` is the receipt generated by the transaction, including the event logs, similar to the[ Ethereum transaction receipt](https://web3js.readthedocs.io/en/v1.2.0/web3-eth.html#gettransactionreceipt).

**Note** : You can also use `pando.GetBlock` to retrieve all the transactions in a block. The transaction details in the `pando.GetBlock` response should also contain the above fields.

Shell

```shell
// Request
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"pando.GetTransaction","params":[{"hash":"0x191b8da0fce91430b6b430405323d26025cb8602c5485c4a259c113f860725ab"}],"id":1}' http://localhost:16888/rpc

// Result
{
    "block_hash": "0xb404521b57caec85449f9e328e8c93e418ffd69b6b22da42f040e1b906491dc0",
    "block_height": "13594165",
    "hash": "0x191b8da0fce91430b6b430405323d26025cb8602c5485c4a259c113f860725ab",
    "receipt": {
        "ContractAddress": "0xc357a28c0285f6c45a7ff7e8c4cc92fad0b34114",
        "EvmErr": "",
        "EvmRet": "",
        "GasUsed": 182650,
        "Logs": [
            {
                "address": "0xc357a28c0285f6c45a7ff7e8c4cc92fad0b34114",
                "data": "",
                "topics": [
                    "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
                    "0x0000000000000000000000000000000000000000000000000000000000000000",
                    "0x00000000000000000000000029917bf58d80815e3dd93b7e4441b405e3d41588",
                    "0x00000000000000000000000000000000000000000000000000000000000000cb"
                ]
            }
        ],
        "TxHash": "0x191b8da0fce91430b6b430405323d26025cb8602c5485c4a259c113f860725ab"
    },
    "status": "finalized",
    "transaction": {
        "data": "QNCXwwAAAAAAAAAAAAAAACmRe/WNgIFePdk7fkRBtAXj1BWI",
        "from": {
            "address": "0x29917bf58d80815e3dd93b7e4441b405e3d41588",
            "coins": {
                "PandoWei": "0",
                "PTXWei": "10000"
            },
            "sequence": "21",
            "signature": "0xc9fb1b288bb68adca3d8516e5c7de73a803b93f72bec7562ca531814f195cbca379ecdc4758f57a8e72702a5967177e597fa0d892239eac6555c81d589a4811a1b"
        },
        "gas_limit": "200915",
        "gas_price": "4000000000000",
        "to": {
            "address": "0xc357a28c0285f6c45a7ff7e8c4cc92fad0b34114",
            "coins": {
                "PandoWei": "0",
                "PTXWei": "0"
            }
        }
    },
    "type": 7
}
```

### GetPendingTransactions

This API returns the pending transactions in the mempool.

**RPC Method:** pando.GetPendingTransactions

**Returns**

* tx\_hashes: the hashes of the transactions pending in the mempool\*

**Example**

Shell

```shell
// Request
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"pando.GetPendingTransactions","params":[],"id":1}' http://localhost:16888/rpc

// Result
{
	"jsonrpc": "2.0",
	"id": 1,
	"result": {
		"tx_hashes": ["0x61ed06b78fededbbd262f95f321d7e48dee81e9b1e493b7f4d42c6bf7afd4b27", "0xc4162541f5e9f283bd9c3beb2798a4a2539b567dd35f52edefde7063f985ab17", "0xc63f2a5bbdc9bc34acde6b800ffd795e7794faa8c07c7c5606fa6cb16513779e", "0xce31bd8d44b1747e8c727bf54aafc7886a0c219d4c79f1245926d4d1244fed8c", "0x2fd317b7c35ea9d1775defd332edc0194c541042090884b4c1d06813b9fe601a", "0x98f3f180abdc756c6443b204b79fcb468bed8e6924da0004159ba686f47d4bd9", "0x6546f2c83405178821d88f1649d7b9f0ebbcde2d9dea59df55bfc7a5e5774267", "0x4a638c8ac1e926447258934be1766f24450856482375a8b7da2f902a4975d28a", "0x8ddc181dd80732961f2886402120ba1568deacbc55ecbfc26b1cf1bddd78c664", "0x14d430ca0c0a208e6bce3c89fcc8664fd4421ce72231ae161672b1b9d575c4e8"]
	}
}
```

## Tx APIs

### BroadcastRawTransaction

This API submits the given raw transaction to the blockchain, and returns only after the transaction to be included in the blockchain, or timed out (i.e. synchronous call).

**RPC Method:** pando.BroadcastRawTransaction

**Query Parameters**

* tx\_bytes: the signed transaction bytes

**Returns**

* hash: the hash of the transaction
* block: the details of the block that contains the transaction

**Example**

Shell

```shell
// Request
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"pando.BroadcastRawTransaction","params":[{"tx_bytes":"02f8a4c78085e8d4a51000f86ff86d942e833968e5bb786ae419c4d13189fb081cc43babd3888ac7230489e800008901158e46f1e875100015b841c2daae6cab92e37308763664fcbe93d90219df5a3520853a9713e70e734b11f27a43db6b77da4f885213b45a294c2b4c74dc9a018d35ba93e5b9297876a293c700eae9949f1233798e905e173560071255140b4a8abd3ec6d3888ac7230489e800008901158e460913d00000"}],"id":1}' http://localhost:16888/rpc

// Result
{
	"jsonrpc": "2.0",
	"id": 1,
	"result": {
		"hash": "0x0a495698654ff5372ef8936eca727c25b975ea0f7e5ebea282e3c86017dfe521",
		"block": {
			"ChainID": "privatenet",
			"Epoch": 40186,
			"Height": 20094,
			"Parent": "0x6797d42ff724a47e9dfd3aa425e2a4f06f40b64fd347ca8c9ebb43d08cb58847",
			"HCC": {
				"Votes": {},
				"BlockHash": "0x6797d42ff724a47e9dfd3aa425e2a4f06f40b64fd347ca8c9ebb43d08cb58847"
			},
			"TxHash": "0xbed5492c96d8251c2f0846a2d12d7a17eb88966a736fa0e8f96af36ed3ffaa74",
			"ReceiptHash": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
			"Bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
			"StateHash": "0xd2b1fa73461fe80d266933033df073a2eb5b82d16cad46f2f74fa2b575adbc88",
			"Timestamp": 1548272003,
			"Proposer": "0x2e833968e5bb786ae419c4d13189fb081cc43bab",
			"Signature": "0x514b731086640c79122f81db1ac1a142d39a92393affb3cbaa09df395dbb441a4b735a66d0da1a52887b66a155033e51b36584dd14b68616fe30b0f2a3f434fa01"
		}
	}
}
```

### BroadcastRawTransactionAsync

This API submits the given raw transaction to the blockchain, and returns immediately (i.e. asynchronous call).

**RPC Method:** pando.BroadcastRawTransactionAsync

**Query Parameters**

* tx\_bytes: the signed transaction bytes\*

**Returns**

* hash: the hash of the transaction\*

**Example**

Shell

```shell
// Request
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"pando.BroadcastRawTransactionAsync","params":[{"tx_bytes":"02f8a4c78085e8d4a51000f86ff86d942e833968e5bb786ae419c4d13189fb081cc43babd3888ac7230489e800008901158e46f1e875100016b841393e2eba6241482098cf11ef4dd869209d7ebd716397f3c862ca5b762bbf403006b1fa009786102383c408cabdf7450c1c73d4dd4a20d3b48a39a88ffe0ecb0e01eae9949f1233798e905e173560071255140b4a8abd3ec6d3888ac7230489e800008901158e460913d00000"}],"id":1}' http://localhost:16888/rpc

// Result
{
	"jsonrpc": "2.0",
	"id": 1,
	"result": {
		"hash": "0xccc7ba0360108369eaebfa0899858bf76a40c6e10d14a93c75697f42a7d33c50"
	}
}
```

## Call Smart Contract

### CallSmartContract

This API simulates the smart contract execution locally without submitting the smart contract transaction to the blockchain. It is useful to evaluate the execution result, calculate the gas cost, etc.

**RPC Method:** pando.CallSmartContract

**Query Parameters**

* sctx\_bytes: the signed transaction bytes

**Returns**

* vm\_return: the return of the virtual machine
* contract\_address: the address of the corresponding smart contract
* gas\_used: amount of gas used for the smart contract execution
* vm\_error: error returned by the virtual machine if any

**Example**

## PandoCli APIs

## Account APIs

### NewKey

This API creates a new account (i.e. a private key/address pair), and encrypts the private key under \~/.pandocli/keys/encrypted/ by default.

**RPC Method:** `pandocli.NewKey`

**Query Parameters**

* password: the password for the new account

**Returns**

* address: the address of the newly created account

**Example**

Shell

```shell
// Request
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"pandocli.NewKey","params":[{"password":"qwertyuiop"}],"id":1}' http://localhost:16889/rpc

// Result
{
	"jsonrpc": "2.0",
	"id": 1,
	"result": {
		"address": "0x8318dd49f83A2684E30d5fB50cD0D3D69aA82EAd"
	}
}
```

### ListKeys

This API lists the addresses of all the accounts on the local machine (i.e. under \~/.pandocli/keys/encrypted/)

**RPC Method:** `pandocli.ListKey`

**Query Parameters**

* None

**Returns**

* addresses: the addresses of the accounts\*

**Example**

Shell

```shell
// Request
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"pandocli.ListKeys","params":[],"id":1}' http://localhost:16889/rpc

// Result
{
	"jsonrpc": "2.0",
	"id": 1,
	"result": {
		"addresses": ["0x0d2fD67d573c8ecB4161510fc00754d64B401F86", "0x21cA457E6E34162654aDEe28bcf235ebE5eee5De", "0x2E833968E5bB786Ae419c4d13189fB081Cc43bab", "0x36Cb7E4dFBbE9508B3A2a331f171E4F6254E213f", "0x636524F8318bCE66C2D2d3159980ad487DF0eC2D", "0x70f587259738cB626A1720Af7038B8DcDb6a42a0", "0x8318dd49f83A2684E30d5fB50cD0D3D69aA82EAd", "0x8fc9fB79a8aa0F9D13156A3CDD74200F75895468", "0xA47B89c94a50C32CEACE9cF64340C4Dce6E5EcC6", "0xa5cdB2B0306518fb37b28bb63A1B2590FdE9b747", "0xcd56123D0c5D6C1Ba4D39367b88cba61D93F5405"]
	}
}
```

### UnlockKey

This API unlocks an account. Only unlocked accounts are allowed to send out PTX tokens.

**RPC Method:** `pandocli.UnlockKey`

**Query Parameters**

* address: The address of the account to be unlocked
* password: The password for the account

**Returns**

* unlocked: A boolean indicating if the account is actually unlocked

**Example**

Shell

```shell
// Request
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"pandocli.UnlockKey","params":[{"address":"0x2E833968E5bB786Ae419c4d13189fB081Cc43bab", "password":"qwertyuiop"}],"id":1}' http://localhost:16889/rpc

// Result
{
	"jsonrpc": "2.0",
	"id": 1,
	"result": {
		"unlocked": true
	}
}
```

### LockKey

This API locks an account. A locked account cannot send out PTX tokens.

**RPC Method:** `pandocli.LockKey`

**Query Parameters**

* address: The address of the account to be locked

**Returns**

* unlocked: A boolean indicating if the account is still unlocked

**Example**

Shell

```shell
// Request
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"pandocli.LockKey","params":[{"address":"0x2E833968E5bB786Ae419c4d13189fB081Cc43bab"}],"id":1}' http://localhost:16889/rpc

// Result
{
	"jsonrpc": "2.0",
	"id": 1,
	"result": {
		"unlocked": false
	}
}
```

### IsKeyUnlocked

This API returns whether an account is currently unlocked.

**RPC Method:** `pandocli.IsKeyUnlocked`

**Query Parameters**

* address: The address of the account to be checked

**Returns**

* unlocked: A boolean indicating if the account is still unlocked

**Example**

Shell

```shell
// Request
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"pandocli.IsKeyUnlocked","params":[{"address":"0x2E833968E5bB786Ae419c4d13189fB081Cc43bab"}],"id":1}' http://localhost:16889/rpc

// Result
{
	"jsonrpc": "2.0",
	"id": 1,
	"result": {
		"unlocked": false
	}
}
```

## Tx APIs

### Send

This API sends the PTX tokens. Note the API call can send PTX tokens, or both in one shot.

**RPC Method:** pandocli.Send

**Query Parameters**

* chain\_id: ID of the chain
* from: The address of the account to send tokens from
* to: The address of the receipient account
* ptxwei: The amount of PTX tokens to be sent (in PTXWei, 1 PTX = 10^18 PTXWei)
* fee: The transaction fee in PTXWei
* sequence: The expected sequence number of the from account
* async: A boolean flag. If async is set to false, the RPC call will wait until the transaction has been included in a block, or a timeout reached. Otherwise, the RPC call will return immediately with the transaction hash.

**Returns**

* hash: the hash of the transaction
* block: the details of the block that has included the transaction

**Example**

Shell

```shell
// Async Request
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"pandocli.Send","params":[{"chain_id":"privatenet", "from":"0x2E833968E5bB786Ae419c4d13189fB081Cc43bab", "to":"0xA47B89c94a50C32CEACE9cF64340C4Dce6E5EcC6", "pandowei":"0", "ptxwei":"88000000000000000000", "fee":"1000000000000", "sequence":"6", "async":true}],"id":1}' http://localhost:16889/rpc

// Async Result
{
	"jsonrpc": "2.0",
	"id": 1,
	"result": {
		"hash": "0xe3e82ae1e08ca49f85842729bd3c70ba0874d59cca3812fe0807506463851d22",
		"block": null
	}
}

// Sync Request
curl -X POST -H 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"pandocli.Send","params":[{"chain_id":"privatenet", "from":"0x2E833968E5bB786Ae419c4d13189fB081Cc43bab", "to":"0xA47B89c94a50C32CEACE9cF64340C4Dce6E5EcC6", "pandowei":"0", "ptxwei":"88000000000000000000", "fee":"1000000000000", "sequence":"7", "async":false}],"id":1}' http://localhost:16889/rpc

// Sync Result
{
	"jsonrpc": "2.0",
	"id": 1,
	"result": {
		"hash": "0xd4dfa1b763cac0c18c816e31ff585c01f2c4f2604dfff01cb6638d6d19e1bd1e",
		"block": {
			"ChainID": "privatenet",
			"Epoch": 170511,
			"Height": 170472,
			"Parent": "0xe36483c52eeee44634038252bb33dfe6b70c439c94c89236c6f18c1a4a676e01",
			"HCC": {
				"Votes": {},
				"BlockHash": "0xe36483c52eeee44634038252bb33dfe6b70c439c94c89236c6f18c1a4a676e01"
			},
			"TxHash": "0xff0d7f1bd6aa699369a935de46c287b30917958c6dbd2d542d31548eaf279525",
			"ReceiptHash": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
			"Bloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
			"StateHash": "0x49374ccea64633a51358816d29a55f372d0fbe7e2f9cb1447ddd2c7519fc17e5",
			"Timestamp": 1550129583,
			"Proposer": "0x2e833968e5bb786ae419c4d13189fb081cc43bab",
			"Signature": "0x96dad1ff2ccc4eb2e18ca99f488cb9d6e6f3333c53a3347d7f8ded5f7301b613763bf0301a85b8f8e7342858c29dd1b262b1b6bdb9552fa5c9b6b61a9b4f6d5c01"
		}
	}
}
```

<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.pandoproject.org/pando-network-docs/apis/tx-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
