UnpChain Testnet RPC and WebSocket Access | Explorer for Interaction

RPC URL: https://rpc.unpchain.com Testnet URL: https://test.unpchain.com
Mainnet URL: https://main.unpchain.com
WebSocket URL: ws://test.unpchain.com
Explorer: https://explorer.unpchain.com

This documentation provides examples and guidance for deploying smart contracts, interacting with them, creating tokens, and transferring tokens on the UnpChain testnet using raw JSON-RPC calls with cURL.


Prerequisites

  • Compile Solidity contracts with version ≤ 0.8.19 (via Remix or solc)
  • Contract bytecode and ABI
  • Your wallet address and private key for transaction signing
  • Tools for offline signing (e.g., ethers.js, web3.js)

1. Check Blockchain Connection

Get latest block number:

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \ -H "Content-Type: application/json" \ https://testnet.unpchain.com

2. Deploy a Smart Contract

2.1 Prepare for Deployment

You need to sign the deployment transaction offline, then send via RPC.

2.2 Sign Deployment Transaction (using ethers.js)

const { ethers } = require("ethers"); const provider = new ethers.providers.JsonRpcProvider("https://testnet.unpchain.com"); const wallet = new ethers.Wallet("YOUR_PRIVATE_KEY", provider); const bytecode = "YOUR_CONTRACT_BYTECODE"; // compiled contract bytecode const abi = [ /* your contract ABI */ ]; async function signAndSend() { const tx = { nonce: await wallet.getTransactionCount(), gasLimit: 3000000, gasPrice: await provider.getGasPrice(), data: bytecode, value: 0, chainId: 1 // verify chainId if different }; const signedTx = await wallet.signTransaction(tx); console.log("Signed transaction:", signedTx); // Send this signed transaction via curl }

2.3 Submit Raw Signed Transaction

curl -X POST --data '{ "jsonrpc":"2.0", "method":"eth_sendRawTransaction", "params":["SIGNED_RAW_TRANSACTION_HEX"], "id":1 }' -H "Content-Type: application/json" https://testnet.unpchain.com

Replace "SIGNED_RAW_TRANSACTION_HEX" with your own.

2.4 Get Transaction Receipt to Find Contract Address

curl -X POST --data '{ "jsonrpc":"2.0", "method":"eth_getTransactionReceipt", "params":["TRANSACTION_HASH"], "id":1 }' -H "Content-Type: application/json" https://testnet.unpchain.com

3. Interacting with a Deployed Contract

3.1 Call Read-Only Function (eth_call)

For a get() function (e.g., storedData):

curl -X POST --data '{ "jsonrpc":"2.0", "method":"eth_call", "params":[{"to":"CONTRACT_ADDRESS","data":"0x6d4ce63c"}, "latest"], "id":1 }' -H "Content-Type: application/json" https://testnet.unpchain.com

(Replace with the correct function ID)


3.2 Call State-Changing Function (set())

Encode set(uint256) data (e.g., set(42)):

DATA="0x60fe47b1000000000000000000000000000000000000000000000000000000000000002a"

Sign offline and send raw transaction similarly.


4. Create an ERC-20 Token

4.1 Compile ERC-20 Contract

Use Solidity ≤ 0.8.19 compatible code.

4.2 Deploy Token Contract

Follow deployment steps as in Section 2.


5. Transfer Tokens (ERC-20)

5.1 Encode transfer(address to, uint256 amount)

  • Method ID: 0xa9059cbb
  • Prepare data:
RECIPIENT="0xRecipientAddress" AMOUNT=1000 # smallest unit # Remove '0x' prefix RECIPIENT_HEX=$(echo "$RECIPIENT" | sed 's/^0x//') RECIPIENT_PAD=$(printf "%064s" "$RECIPIENT_HEX") AMOUNT_HEX=$(printf "%064x" "$AMOUNT") DATA="0xa9059cbb$RECIPIENT_PAD$AMOUNT_HEX"

5.2 Transact to Transfer Tokens

Offline sign your transaction with your private key, then send:

curl -X POST --data '{ "jsonrpc":"2.0", "method":"eth_sendRawTransaction", "params":["SIGNED_RAW_TX_FOR_TRANSFER"], "id":1 }' -H "Content-Type: application/json" https://testnet.unpchain.com

6. Checking Transaction Status

curl -X POST --data '{ "jsonrpc":"2.0", "method":"eth_getTransactionReceipt", "params":["TX_HASH"], "id":1 }' -H "Content-Type: application/json" https://testnet.unpchain.com

Exploration and Chain Interaction Tools

  • Explorer: https://testnet.unpchain.com — use this to view transactions, verify contract deployments, and explore blocks or addresses visually.
  • WebSocket Endpoint: ws://test-net.unpchain.com — for real-time WebSocket interactions, subscribing to events or new blocks (requires WebSocket client).

Summary Workflow

  1. Query info via RPC (latest block, account nonce, gas price)
  2. Create and sign transactions offline
  3. Send raw transactions with eth_sendRawTransaction
  4. Check status using eth_getTransactionReceipt
  5. Use Explorer for visual checks

Notes

  • Always compile contracts with Solidity ≤ 0.8.19.
  • Offline signing enhances security.
  • Use tools like ethers.js, web3.js, or SDKs for encoding/signing.