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.
ethers.js, web3.js)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
You need to sign the deployment transaction offline, then send via RPC.
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 }
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.
curl -X POST --data '{ "jsonrpc":"2.0", "method":"eth_getTransactionReceipt", "params":["TRANSACTION_HASH"], "id":1 }' -H "Content-Type: application/json" https://testnet.unpchain.com
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)
set())Encode set(uint256) data (e.g., set(42)):
DATA="0x60fe47b1000000000000000000000000000000000000000000000000000000000000002a"
Sign offline and send raw transaction similarly.
Use Solidity ≤ 0.8.19 compatible code.
Follow deployment steps as in Section 2.
transfer(address to, uint256 amount)0xa9059cbbRECIPIENT="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"
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
curl -X POST --data '{ "jsonrpc":"2.0", "method":"eth_getTransactionReceipt", "params":["TX_HASH"], "id":1 }' -H "Content-Type: application/json" https://testnet.unpchain.com
ws://test-net.unpchain.com — for real-time WebSocket interactions, subscribing to events or new blocks (requires WebSocket client).eth_sendRawTransactioneth_getTransactionReceiptethers.js, web3.js, or SDKs for encoding/signing.