當經過sendTransaction發出交易以後,transaction並無當即上鍊,因此要先經過txpool.status.pending來看看若是大於0,說明你的結點中有pending的transaction。(或者經過eth.getBlock("pending")來查看你的交易是否在pending塊中)web
固然若是沒有上鍊,這個交易是在你的結點中發出的,能夠直接經過getTransaction來獲取交易,返回的結果中blockHash爲零,blockNumber爲null:json
{ blockHash: '0x0000000000000000000000000000000000000000000000000000000000000000', blockNumber: null, from: '0xdfb1b9b8693366eb9044ffd8c00058abc904558b', gas: 90000, gasPrice: ..., hash: '0x0b4f742149fc3018a168950b56786846da99675913dbc043971cbe25ac7792ac', input: '0x48656c6c6f20576f726c64', nonce: 2, to: null, transactionIndex: null, value: ...
可是他奶奶的,若是有一種狀況,交易成功了,可是out of gas,以前的邏輯都是成功了,也上鍊了,可是交易卻沒有成功,我在轉erc20幣的時候遇到很多這種狀況,這怎搞?api
經過debug_traceTransaction來看看這筆交易有沒有error。app
首先你的結點rpc必須是開放debug的:curl
geth --rpc --rpcapi "eth,net,web3,debug" console
而後調用debug_traceTransaction:url
curl localhost:8545 -X POST --header 'Content-type: application/json' --data '{"jsonrpc":"2.0", "method":"debug_traceTransaction", "params":["0x3684f071b34da1116282ee88a106a8f2a266d273ef7d8964957f65128fb58d77", {}], "id":1}'
結果相似這樣:debug
{ gas: 85301, returnValue: "", structLogs: [{ depth: 1, error: "", gas: 162106, gasCost: 3, memory: null, op: "PUSH1", pc: 0, stack: [], storage: {} }, /* snip */ { depth: 1, error: "", gas: 100000, gasCost: 0, memory: ["0000000000000000000000000000000000000000000000000000000000000006", "0000000000000000000000000000000000000000000000000000000000000000", "0000000000000000000000000000000000000000000000000000000000000060"], op: "STOP", pc: 120, stack: ["00000000000000000000000000000000000000000000000000000000d67cbec9"], storage: { 0000000000000000000000000000000000000000000000000000000000000004: "8241fa522772837f0d05511f20caa6da1d5a3209000000000000000400000001", 0000000000000000000000000000000000000000000000000000000000000006: "0000000000000000000000000000000000000000000000000000000000000001", f652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d3f: "00000000000000000000000002e816afc1b5c0f39852131959d946eb3b07b5ad" } }]
從structLogs中一個個看是否有error非null的存在,若是有說明實際是失敗了3d