技术参考
“技术参考”部分为开发者提供了 WSCChain 的核心技术细节,包括 API 接口、智能合约 ABI、共识机制参数和其他关键配置信息。本章节旨在作为开发者的技术手册,帮助您与 WSCChain 主网交互、调试应用并优化开发流程。WSCChain 的设计注重高性能、低成本和 EVM 兼容性,所有参考信息均基于此特性构建。
1. JSON-RPC API 参考
JuChain 提供标准的 JSON-RPC API,支持与区块链交互。
1.1 配置
协议:HTTP/HTTPS 或 WebSocket(wss://rpc.onwsc.com/ws)
1.2 常用方法
eth_blockNumber
描述:返回当前区块高度。
请求:
{ "jsonrpc": "2.0", "method": "eth_blockNumber", "params": [], "id": 1 }响应:
{ "jsonrpc": "2.0", "id": 1, "result": "0x1a2b3c" // 十六进制区块高度 }示例(cURL):
curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' https://rpc.onwsc.com/
eth_getBalance
描述:查询指定地址的 WSC 余额。
参数:
address:20 字节地址(如"0x1234567890abcdef1234567890abcdef12345678")。block:区块标签(如"latest")。
请求:
{ "jsonrpc": "2.0", "method": "eth_getBalance", "params": ["0x1234567890abcdef1234567890abcdef12345678", "latest"], "id": 2 }响应:
{ "jsonrpc": "2.0", "id": 2, "result": "0x16345785d8a0000" // 余额(wei) }
eth_sendRawTransaction
描述:发送已签名的交易。
参数:
rawTx:签名后的交易数据(十六进制字符串)。
请求:
{ "jsonrpc": "2.0", "method": "eth_sendRawTransaction", "params": ["0xf86c018502540be400825208941234567890abcdef1234567890abcdef1234567888016345785d8a00008025a0..."], "id": 3 }响应:
{ "jsonrpc": "2.0", "id": 3, "result": "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890" // 交易哈希 }
eth_call
描述:调用智能合约的只读方法。
参数:
transaction:包含to(合约地址)和data(方法签名及参数)。block:区块标签。
请求:
{ "jsonrpc": "2.0", "method": "eth_call", "params": [{"to": "0xContractAddress", "data": "0x6d4ce63c"}, "latest"], "id": 4 }响应:
{ "jsonrpc": "2.0", "id": 4, "result": "0x000000000000000000000000000000000000000000000000000000000000002a" // 返回值(如 42) }
1.3 完整 API 列表
更多方法(如
eth_getTransactionByHash、eth_getBlockByNumber)与 Ethereum API 兼容,请参考 Ethereum JSON-RPC 文档。
2. 智能合约 ABI
以下是 JuChain 核心合约的 ABI 示例,用于与 WSC 代币和其他功能交互。
2.1 WSC 代币 ABI
合约地址:
0x253Ef4d73b20a1F55651B8788238dad355AbB11F标准:ERC-20。
核心方法:
[ { "constant": true, "inputs": [{"name": "_owner", "type": "address"}], "name": "balanceOf", "outputs": [{"name": "balance", "type": "uint256"}], "type": "function" }, { "constant": false, "inputs": [ {"name": "_to", "type": "address"}, {"name": "_value", "type": "uint256"} ], "name": "transfer", "outputs": [{"name": "success", "type": "bool"}], "type": "function" }, { "constant": false, "inputs": [ {"name": "_spender", "type": "address"}, {"name": "_value", "type": "uint256"} ], "name": "approve", "outputs": [{"name": "success", "type": "bool"}], "type": "function" } ]
3. WPoSA 参数
WPoSA(WSCChain Proof of Stake Authorization)是 WSCChain 的共识机制,以下是关键参数:
3.1 共识参数
区块时间:1 秒。
交易最终确认:1 秒(1 个区块)。
最大核心验证者数量:21。
最小质押要求:10,00 WSC。
验证周期:默认 7200 区块(约 6 小时),动态调整范围 3600-14400 区块。
3.2 容错性
拜占庭容错:可容忍 1/3 验证者故障或恶意行为(最多 7 个核心验证者)。
惩罚机制:连续 100 个区块未出块,扣除 5% 质押 WSC。
3.3 奖励
区块奖励:每区块获取全部GAS收入,动态调整。
委托奖励分配:验证者与委托者按 70:30 比例分配。
6. 错误码
以下是常见错误及其解决方法:
错误码
描述
解决方法
-32000
余额不足(Insufficient funds)
检查账户余额并获取更多 WSC 代币。
-32603
Gas 不足(Out of gas)
提高交易的 Gas 限制。
429
请求过于频繁(Too Many Requests)
等待 1 分钟后重试,或检查限额。
0x
交易失败(Reverted)
检查合约逻辑或输入参数。
6. 工具与 SDK
6.1 Truffle 配置
示例(
truffle-config.js):Copy
const HDWalletProvider = require("@truffle/hdwallet-provider"); module.exports = { networks: { wscchain: { provider: () => new HDWalletProvider("助记词", "https://rpc.onwsc.com"), network_id: 20180422, gas: 5500000, gasPrice: 1000000000, }, }, };
7. 其他参考
EVM 兼容性:WSCChain 支持所有以太坊操作码(Opcodes),参考 Ethereum Yellow Paper。
区块结构:
头部:版本、前哈希、时间戳、Merkle 根。
主体:交易列表。
状态数据库:基于 MPT,参考 Ethereum Trie。
最后更新于