eos icon indicating copy to clipboard operation
eos copied to clipboard

How to get transaction list by json rpc api ?

Open kevingwang opened this issue 8 years ago • 6 comments

How to get transaction list by json rpc api ?Thanks!

kevingwang avatar Apr 24 '18 06:04 kevingwang

Can you get transactions on your account?

cleos get transactions testaccount 1450928ms thread-0 main.cpp:1435 main ] Failed with error: Key Not Found (6) Key data

Why do I get such a error

remonee avatar Apr 24 '18 06:04 remonee

call 'cleos get transactions -j testaccount' , it will give your result in json

zhky04 avatar Apr 30 '18 14:04 zhky04

Instead of calling cleos , you can get an transaction through RPC interface:

curl  http://127.0.0.1:8888/v1/account_history/get_transaction \
         -X POST -d '{"transaction_id": "your_transaction_id"}'

EOSIO's RPC documentation didn't document this interface, but since cleos itself is interacting nodeos's REST api, so basically commands supported by cleos can be called on nodeos directly.

cleos's source code locates in programs/cleos/. Go to main.cpp and locates main() function, inside which defines how cleos interacts with nodeos. For example:

https://github.com/EOSIO/eos/blob/4cbf721787e1c04075f1628afb5ecbe5bb576239/programs/cleos/main.cpp#L1063-L1074

This block of code reads the transaction id passed to cleos and wrapped it to a JSON object {"transaction_id": "your_transaction_id"}, then calls nodeos's get_transaction endpoint.

The other thing noteworthy is, each RPC interface have different endpoint. For example, get_block RPC's endpoint is /chain/get_block, however, for get_transaction it is /account_history/get_transaction, the endpoints of each RPC interface are defined in programs/cleos/httpc.hpp.

chengevo avatar May 01 '18 07:05 chengevo

@chengevo is correct here. However, in the latest version account_history_api is deprecated and is replaced by history_api. With history_api, it will be like this

curl  http://127.0.0.1:8888/v1/history/get_transaction \
         -X POST -d '{"transaction_id": "your_transaction_id"}'

andriantolie avatar Jul 18 '18 09:07 andriantolie

To anyone coming back to read this in the future, this RPC method has been changed again, where the parameter is now id instead of transaction_id:

curl  http://127.0.0.1:8888/v1/history/get_transaction \
        -X POST -d '{"id": "your_transaction_id"}'

kklash avatar Sep 30 '18 05:09 kklash

curl  https://proxy.eosnode.tools/v1/history/get_transaction \
         -X POST -d '{"id":"5781aa1178a6b6d8798eee8fe72c5a799271ae74737e43a0a57eef27ce9b2e55"}'

change the transaction_id to id

qyvlik avatar Nov 05 '18 12:11 qyvlik