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 does the method determine the transaction type of 'approved' or 'transferred'? #111

Open
gedowangvs97 opened this issue Nov 15, 2023 · 7 comments

Comments

@gedowangvs97
Copy link

“getTransactionById” How does the method determine the transaction type of 'approved' or 'transferred'? Or is there any way to tell the difference?
Demo TxId:
232a8da14f777c360ec398568ae828852a60d64507fb482b118c922b1cb8cdbe
42eb88afe779f8e639cc758f688b192f9f2988db69a6f0c87e3282347b3b7635

@ferdinand026
Copy link

@gedowangvs97 For Tronscan, 'approved' or 'transferred' is only a description of the contract method called in this transaction. For the method specified by TRC standard, Tronscan will translate it to more readable statement with more obvious key information, for example, for approve transaction.

About how to determine the transaction type of the transaction which get through "getTransactionById" API, "raw_data.contract[0].type is the transaction type. For the type of triggerSmartContract, the invocation method can be obtained through "raw_data. contract[0]. parameter. value. data" filed, and the first 4 bytes is the method, we need to decode the data, please refer to the guide.

@Aiden-777
Copy link

Aiden-777 commented Nov 18, 2023

public static final String APPROVE_FUNC_ID_BY_KECCAK256 =
        Hex.toHexString(
                new Keccak.Digest256().digest("approve(address,uint256)".getBytes())
        ).substring(0, 8);
String data = Hex.toHexString(triggerSmartContract.getData().toByteArray());

if (!TronConstants.APPROVE_FUNC_ID_BY_KECCAK256 .equals(funcId)) {
    ...
}

@gedowangvs97
Copy link
Author

How to get this fundId field?

if (!TronConstants.APPROVE_FUNC_ID_BY_KECCAK256 .equals(funcId)) {
...
}

@Aiden-777
Copy link

https://developers.tron.network/docs/parameter-encoding-and-decoding

String funcId = data.substring(0, 8);

@gedowangvs97
Copy link
Author

approve TxId:
232a8da14f777c360ec398568ae828852a60d64507fb482b118c922b1cb8cdbe

String funcId = data.substring(0, 8);
// substring:095ea7b3

public static final String APPROVE_FUNC_ID_BY_KECCAK256 =
Hex.toHexString(
new Keccak.Digest256().digest("approve(address, uint256)".getBytes())
).substring(0, 8);
// 8b069f2a

Why are the above two values different?

@ferdinand026
Copy link

approve TxId: 232a8da14f777c360ec398568ae828852a60d64507fb482b118c922b1cb8cdbe

String funcId = data.substring(0, 8); // substring:095ea7b3

public static final String APPROVE_FUNC_ID_BY_KECCAK256 = Hex.toHexString( new Keccak.Digest256().digest("approve(address, uint256)".getBytes()) ).substring(0, 8); // 8b069f2a

Why are the above two values different?

There should be no any space in the function method. Remove all the spaces and it will be "approve(address,uint256)"

@Aiden-777
Copy link

approve TxId: 232a8da14f777c360ec398568ae828852a60d64507fb482b118c922b1cb8cdbe
String funcId = data.substring(0, 8); // substring:095ea7b3
public static final String APPROVE_FUNC_ID_BY_KECCAK256 = Hex.toHexString( new Keccak.Digest256().digest("approve(address, uint256)".getBytes()) ).substring(0, 8); // 8b069f2a
Why are the above two values different?

There should be no any space in the function method. Remove all the spaces and it will be "approve(address,uint256)"

Yes, I made a stupid mistake and have corrected it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants