cfx_sendRawTransaction 接口错误
这些错误是由 Conflux 协议的官方实现 conflux-rust定义的。
:::
在Conflux Core空间中通过cfx_sendRawTransaction 方法发送交易时,可能会因为不正确的交易构建或其他问题而出现一些错误。 本指南涵盖了常见错误及其解决方法。
余额不足
{
    "jsonrpc": "2.0",
    "id": "15922956697249514502",
    "error": {
        "code": -32602,
        "message": "Invalid parameters: tx",
        "data": "\"Transaction 0xf34740b7f033b13b8670df91f24537e756700a32f17e5e09a7d297701cec6859 is discarded due to out of balance, needs 9000000000420000000000000 but account balance is 90095849479680000000000\""
    }
}
Nonce 错误
使用已执行过的nonce
{
    "jsonrpc": "2.0",
    "id": "15922956697249514502",
    "error": {
        "code": -32602,
        "message": "Invalid parameters: tx",
        "data": "\"Transaction 0x4a2cfa73267139d965ab86d41f2af16db09e62ff92a5abffd7f8e743f36f327c is discarded due to a too stale nonce\""
    }
}
**解决方案:**将nonce更改为第一个未使用的nonce。
使用一个已经发送到交易池的nonce
{
    "jsonrpc": "2.0",
    "id": "15922956697249514502",
    "error": {
        "code": -32602,
        "message": "Invalid parameters: tx",
        "data": "\"tx already exist\""
    }
  }
或者
{
    "jsonrpc": "2.0",
    "id": "15922956697249514502",
    "error": {
        "code": -32602,
        "message": "Invalid parameters: tx",
        "data": "Tx with same nonce already inserted. to replace it, you need to specify a gas price > {}"
    }
}
**解决方案:**交易已经发送到交易池。 请使用相同的nonce更新或替换它,同时修改相应的字段,并使用更高的gasPrice值重新发送。
使用过大的nonce
{
    "jsonrpc": "2.0",
    "id": "15922956697249514502",
    "error": {
        "code": -32602,
        "message": "Invalid parameters: tx",
        "data":"\"Transaction 0xc875a03e1ce01268931a1a428d8f8313714ab5eb9c2b626bd327af7e5c3e8c03 is discarded due to in too distant future\""
    }
  }
**解决方案:**将nonce更改为第一个未使用的nonce。
与gas相关的问题
Gas too small (<21000) or too large (>15m)
{
    "jsonrpc": "2.0",
    "id": "15922956697249514502",
    "error": {
        "code": -32602,
        "message": "Invalid parameters: tx",
        "data": "\"NotEnoughBaseGas { required: 21000, got: 2000 }\""
    }
}
**解决方法:**将gas字段改为正确的字段。
{
    "jsonrpc": "2.0",
    "id": "15922956697249514502",
    "error": {
        "code": -32602,
        "message": "Invalid parameters: tx",
        "data": "\"transaction gas 20000000 exceeds the maximum value 15000000, the half of pivot block gas limit\""
    }
}
**解决方法:**将gas字段改小一点。 最大值为1500万。
无效的gasPrice
GasPrice价格设置为0
{
    "jsonrpc": "2.0",
    "id": "15922956697249514502",
    "error": { 
      "code": -32602,
      "message": "Invalid parameters: tx", 
      "data": "\"ZeroGasPrice\"" 
    }
}
解决方法: 使用cfx_gasPrice的返回值作为gasPrice。
GasPrice低于最低的gas价格
{
    "jsonrpc": "2.0",
    "id": "15922956697249514502",
    "error": {
        "code": -32602,
        "message": "Invalid parameters: tx",
        "data": "\"transaction gas price 1 less than the minimum value 20000000000\""
    }
}
超过数据大小限制
交易的大小有限制,最大为 200K。
epochHeight错误
{
    "jsonrpc": "2.0",
    "id": "15922956697249514502",
    "error": {
        "code": -32602,
        "message": "Invalid parameters: tx",
        "data": "\"EpochHeightOutOfBound { block_height: 53800739, set: 0, transaction_epoch_bound: 100000 }\""
    }
}
**解决方法:**使用cfx_epochNumber的返回值作为epochHeight
chainId不匹配
{
    "jsonrpc": "2.0",
    "id": "15922956697249514502",
    "error": {
        "code": -32602,
        "message": "Invalid parameters: tx",
        "data": "\"ChainIdMismatch { expected: 1, got: 2 }\""
    }
}
解决方法: 使用cfx_status返回值中的chainId字段作为chainId。
编码或者签名错误
{
    "jsonrpc": "2.0",
    "id": "15922956697249514502",
    "error": {
        "code": -32602,
        "message": "Invalid parameters: raw",
        "data": "\"RlpIncorrectListLen\""
    }
}
{
    "jsonrpc": "2.0",
    "id": "15922956697249514502",
    "error": {
        "code": -32602,
        "message": "Invalid parameters: raw",
        "data": "\"RlpExpectedToBeList\""
    }
}
{
    "jsonrpc": "2.0",
    "id": "15922956697249514502",
    "error": {
        "code": -32602,
        "message": "Invalid parameters: tx",
        "data": "Can not recover pubkey for Ethereum like tx"
    }
}
解决方法: 确保你正确地使用SDK。
交易池已满
{
    "jsonrpc": "2.0",
    "id": "15922956697249514502",
    "error": {
        "code": -32602,
        "message": "Invalid parameters: tx",
        "data": "txpool is full"
    }
}
或者
{
    "jsonrpc": "2.0",
    "id": "15922956697249514502",
    "error": {
        "code": -32602,
        "message": "Invalid parameters: tx",
        "data": "Failed imported to deferred pool: Transaction Pool is full"
    }
}
**解决方案:**等待一段时间后重新发送交易,并提高交易的gasPrice以增加发送的机会。
处于追赶模式的节点
{
    "jsonrpc": "2.0",
    "id": "15922956697249514502",
    "error": {
        "code": -32077,
        "message": "Request rejected due to still in the catch up mode",
        "data": null
    }
}
**解决方案:**在发送之前,等待节点数据同步到最新。
内部错误
{
    "jsonrpc": "2.0",
    "id": "15922956697249514502",
    "error": {
        "code": -32602,
        "message": "Invalid parameters: tx",
        "data": "Failed to read account_cache from storage: {}"
    }
}