EVM JSONRPC API Reference

P-20 JSONRPC API Reference

The P-20 JSONRPC API provides a comprehensive set of methods to interact with the P-20 blockchain using the JSON-RPC (Remote Procedure Call) protocol. This API allows developers to integrate their applications with the P-20 blockchain and perform various operations, such as querying blockchain data, executing smart contracts, and managing accounts. In this section, we will explore the P-20 JSONRPC API in depth and provide examples of its usage.

JSONRPC Endpoint

The JSONRPC endpoint is the URL that developers can use to connect to the P-20 blockchain network and access its JSONRPC API. The endpoint URL typically follows the format: http://<hostname>:<port>/jsonrpc. Developers can use the HTTP or HTTPS protocol to communicate with the endpoint.

API Methods

The P-20 JSONRPC API provides a wide range of methods categorized into different groups, including blockchain, accounts, transactions, smart contracts, and more. Let's explore some of the commonly used methods within these categories:

1. Blockchain Methods

  • p20_blockNumber: Returns the current block number of the P-20 blockchain.

  • p20_getBlockByNumber: Retrieves information about a specific block based on its number.

  • p20_getTransactionByHash: Retrieves transaction details based on its hash.

2. Transaction Methods

  • p20_sendTransaction: Sends a transaction to the P-20 blockchain for execution.

  • p20_getTransactionReceipt: Retrieves the receipt of a specific transaction.

3. Smart Contract Methods

  • p20_sendRawTransaction: Sends a raw transaction to the P-20 blockchain for execution.

  • p20_call: Executes a call or transaction against a deployed smart contract without modifying the blockchain state.

  • p20_getCode: Retrieves the bytecode of a deployed smart contract.

Examples

Here are a few examples to demonstrate the usage of the P-20 JSONRPC API methods:

  1. Retrieve Block Number:

Request:
{
  "jsonrpc": "2.0",
  "method": "p20_blockNumber",
  "params": [],
  "id": 1
}

Response:
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x5B7"
}
  1. Get Transaction by Hash:

Request:
{
  "jsonrpc": "2.0",
  "method": "p20_getTransactionByHash",
  "params": ["0x1234567890123456789012345678901234567890"],
  "id": 2
}

Response:
{
  "jsonrpc": "2.0",
  "id": 2,
  "result": "0x295A8A5294BCEF"
}
  1. Send Transaction:

Request:
{
  "jsonrpc": "2.0",
  "method": "p20_sendTransaction",
  "params": [
    {
      "from": "0x1234567890123456789012345678901234567890",
      "to": "0x0987654321098765432109876543210987654321",
      "value": "0x12A05F200"
    }
  ],
  "id": 3
}

Response:


{
  "jsonrpc": "2.0",
  "id": 3,
  "result": "0x123ABCDEF"
}

These examples demonstrate how to retrieve the current block number, check the balance of an account, and send a transaction using the P-20 JSONRPC API. Developers can leverage these methods and customize the parameters based on their specific requirements.

Conclusion

The P-20 JSONRPC API provides a powerful interface for developers to interact with the P-20 blockchain and build decentralized applications on top of it. By utilizing the various API methods, developers can query blockchain data, manage accounts, execute smart contracts, and more. The examples provided in this section showcase the basic usage of some commonly used methods, enabling developers to integrate their applications seamlessly with the P-20 blockchain.

Last updated