Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get transaction list by json rpc api ? #2570

Closed
kevingwang opened this issue Apr 24, 2018 · 6 comments
Closed

How to get transaction list by json rpc api ? #2570

kevingwang opened this issue Apr 24, 2018 · 6 comments
Assignees
Labels

Comments

@kevingwang
Copy link

@kevingwang kevingwang commented Apr 24, 2018

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

@remonee

This comment has been minimized.

Copy link

@remonee remonee commented Apr 24, 2018

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

@zhky04

This comment has been minimized.

Copy link

@zhky04 zhky04 commented Apr 30, 2018

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

@chengevo

This comment has been minimized.

Copy link
Contributor

@chengevo chengevo commented May 1, 2018

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:

eos/programs/cleos/main.cpp

Lines 1063 to 1074 in 4cbf721

// get transaction
string transaction_id_str;
auto getTransaction = get->add_subcommand("transaction", localized("Retrieve a transaction from the blockchain"), false);
getTransaction->add_option("id", transaction_id_str, localized("ID of the transaction to retrieve"))->required();
getTransaction->set_callback([&] {
transaction_id_type transaction_id;
try {
transaction_id = transaction_id_type(transaction_id_str);
} EOS_RETHROW_EXCEPTIONS(transaction_id_type_exception, "Invalid transaction ID: ${transaction_id}", ("transaction_id", transaction_id_str))
auto arg= fc::mutable_variant_object( "transaction_id", transaction_id);
std::cout << fc::json::to_pretty_string(call(get_transaction_func, arg)) << std::endl;
});

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.

@andriantolie

This comment has been minimized.

Copy link
Contributor

@andriantolie andriantolie commented Jul 18, 2018

@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"}'
@kklash

This comment has been minimized.

Copy link

@kklash kklash commented Sep 30, 2018

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"}'
@qyvlik

This comment has been minimized.

Copy link

@qyvlik qyvlik commented Nov 5, 2018

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

change the transaction_id to id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants
You can’t perform that action at this time.