How to get transaction list by json rpc api ?
How to get transaction list by json rpc api ?Thanks!
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
call 'cleos get transactions -j testaccount' , it will give your result in json
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 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"}'
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"}'
curl https://proxy.eosnode.tools/v1/history/get_transaction \
-X POST -d '{"id":"5781aa1178a6b6d8798eee8fe72c5a799271ae74737e43a0a57eef27ce9b2e55"}'
change the transaction_id to id