2

Is it possible to access the current transaction ID from within a smart contract?

3

There are two issue on github: this which refers to this. According to these two links, you cannot access directly the transaction id, but the id is a calculated value, so you can compute it in your smart contract. From the second link, you can get this code:

void test_transaction::test_read_transaction() {
   using namespace eosio;
   checksum256 h;
   auto size = transaction_size();
   char buf[size];
   uint32_t read = read_transaction( buf, size );
   eosio_assert( size == read, "read_transaction failed");
   sha256(buf, read, &h);
   printhex( &h, sizeof(h) );
}
1

Here's an updated example using EOSIO CDT 1.6 code syntax

checksum256 get_trx_id() {
    size_t size = transaction_size();
    char buf[size];
    size_t read = read_transaction( buf, size );
    check( size == read, "read_transaction failed");
    return sha256( buf, read );
}

Afterwards you can include get_trx_id method into other parts of your smart contract.

table.emplace( payer, [&]( auto & row ) {
    row.trxid   = get_trx_id();
});
New contributor
user1116928 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.