neodix42 / ton4j

Java libraries for interacting with TON blockchain.
GNU General Public License v3.0
74 stars 24 forks source link

Is it possible to decode msg body using ton4j?? #37

Closed hsmang closed 2 months ago

hsmang commented 2 months ago

I want to decode msg body but I don't know how. Can anyone please let me know if there is any way?

neodix42 commented 2 months ago

yes, please take a look at this sample: https://github.com/neodix42/ton4j/blob/main/tonlib/src/test/java/org/ton/java/tonlib/TestTonlibJson.java#L367

hsmang commented 2 months ago

I did it the way you told me, but it wasn't the answer I wanted. x{D3669639FA8CA1B7B90FC53C6BC01CB6375C96016DAB67F7FC5045BBB18D06E2DC773A9393CEAFC112D398AB6CEF71365DD00875DB0B5B32FB8788F4E19AC60529A9A31766A32C52000000050003} x{42006F81CDEB2F2D0AD964F8E3550D019F51DBEB884E7B650FF96316CB584EA2A8D1161A800000000000000000000000000000000000313233214023262A26ED959CEAB880414243}

I want to change the text that people can read

test transaction https://tonscan.org/tx/gspcs5JTZmRlzKUGiOKYUx2%2F2rWXr1Gu2KBhRx7CX2Q=

plz help...

paulzz826 commented 2 months ago

You can use the methods in the CellSlice class for parameter parsing, and you should confirm the parameter structure with your contract developer

hsmang commented 2 months ago

CellSlice test code has been viewed. But I don't really understand it. Is the boc the body value of in_msg correct? `

   String boc = "te6cckEBAgEAmwABnNNmljn6jKG3uQ/FPGvAHLY3XJYBbatn9/xQRbuxjQbi3Hc6k5POr8ES05irbO9xNl3QCHXbC1sy+4eI9OGaxgUpqaMXZqMsUgAAAAUAAwEAkEIAb4HN6y8tCtlk+ONVDQGfUdvriE57ZQ/5YxbLWE6iqNEWGoAAAAAAAAAAAAAAAAAAAAAAADEyMyFAIyYqJu2VnOq4gEFCQ6E8XQg="; //  in_msg body 

    CellSlice cellSlice = CellSlice.beginParse(CellBuilder.beginCell().fromBoc(Utils.base64ToSignedBytes(boc)).endCell());
    System.out.println("cell address : " + cellSlice.loadAddress().toString(false));

` An error occurs when the above code is executed.

Exception in thread "main" java.lang.Error: Invalid address wc -101:34b1cfd4650dbdc87e29e35e00e5b1bae4b00b6d5b3fbfe2822ddd8c683716e3 at org.ton.java.address.Address.<init>(Address.java:62) at org.ton.java.address.Address.of(Address.java:100) at org.ton.java.cell.CellSlice.loadAddress(CellSlice.java:625) at org.example.Main.main(Main.java:41)

hsmang commented 2 months ago

I solved it!

String comment = cellSlice.loadSnakeString();

Thanks !!!!