1

I'm pulling fight logs from a BSC contract via bscscan API. The data record, which should be a set 6 different values, looks like this: 0x00000000000000000000000000000000000000000000000000000000000b501600000000000000000000000000000000000000000000000000000000030004750000000000000000000000000000000000000000000000000000000000000522000000000000000000000000000000000000000000000000000000000000046300000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000066e52ba3af511

Here is the entire entry record:

 {
                "address": "0x39bea96e13453ed52a734b6aceed4c41f57b2271",
                "topics": [
                    "0x7a58aac6530017822bf3210fccef7efa31f56277f19966bc887bfb11f40ca96d",
                    "0x0000000000000000000000002c238ad3411bdcdc0e4175f9320924ebc335e9e0",
                    "0x000000000000000000000000000000000000000000000000000000000004ce14"
                ],
                "data": "0x00000000000000000000000000000000000000000000000000000000000b501600000000000000000000000000000000000000000000000000000000030004750000000000000000000000000000000000000000000000000000000000000522000000000000000000000000000000000000000000000000000000000000046300000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000066e52ba3af511e",
                "blockNumber": "0x8fb8df",
                "timeStamp": "0x60fb3442",
                "gasPrice": "0x12a05f200",
                "gasUsed": "0x265a1",
                "logIndex": "0x1b8",
                "transactionHash": "0xf6b8279edcf9f5c76d067fc1ca529f7e8fd4f0be4b7e277ba28556e19ed3ced0",
                "transactionIndex": "0x72"
            },

How can I use vanilla PHP to decode this string into the 6 data values as they can be seen here: https://bscscan.com/tx/0xf6b8279edcf9f5c76d067fc1ca529f7e8fd4f0be4b7e277ba28556e19ed3ced0#eventlog

I'd rather not use a W3 or other library.

Any help is appreciated!

1

1 Answer 1

1

It seems that this PHP works for the above:

$data = $tx['data'];
$data_cleaned = str_replace("0x" , "" , $data);
$data_split =  str_split($data_cleaned, 64);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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