Hex-to-Integer Function
A convenience function to convert hex values to integers, useful when working with raw EVM event logs and transactions.
Function name: utils.udf_hex_to_int()
What is it used for: converts hex values into integer
When to use:
When working with raw event logs and data inside the fact_transactions and fact_event_logs tables, you will encounter hexadecimal values, similar to what you find on Etherscan in the ‘Input data’ section or the ‘Logs’ section.
Often you will want to convert these values into integers to get the decoded values. For example, in our Example 2 below, decoding the hex value gives us the NFT token ID. Note that you can use this function is relevant for any EVM data and is not limited to Ethereum data only.
How to use:
Example 1
This would produce ‘8187’ as the result. Note that removing the leading 0’s, to just ‘1ffb’ would also produce the same result.
Example 2
Consider this Etherscan transaction:
If we queried the input_data column for this transaction in the ethereum.core.fact_transactions table, we’d get:
We can rearrange the data above to what we see on Etherscan in the screenshot below:
0x5138b08c 000000000000000000000000b932a70a57673d89f4acffbe830e8ed7f75fb9e0 0000000000000000000000000000000000000000000000000000000000001ffb
![](https://docs.flipsidecrypto.xyz/~gitbook/image?url=https%3A%2F%2F3303628914-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LdEnDLYh6Su5z7LbnEZ%252Fuploads%252FxLbnSpiR4Ci6er9UFCgR%252FScreenshot%25202022-09-14%2520at%252010.33.11%2520AM.png%3Falt%3Dmedia%26token%3D05445395-d187-4525-a382-0bdd65da9269&width=768&dpr=4&quality=100&sign=d362c65a&sv=1)
We can use the substr function to get the string that is associated with ‘auctionId’.
And because it is an integer, we can use the hex to int function to convert it to an integer.
This would result in 8187 which is consistent with using the decode button on Etherscan as shown in the screenshot below.
![](https://docs.flipsidecrypto.xyz/~gitbook/image?url=https%3A%2F%2F3303628914-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252F-LdEnDLYh6Su5z7LbnEZ%252Fuploads%252FK9MsNlcgtWpEvlA04yNc%252FScreenshot%25202022-09-14%2520at%252010.33.24%2520AM.png%3Falt%3Dmedia%26token%3Def873ee2-ba19-4985-bedd-8da639095484&width=768&dpr=4&quality=100&sign=b37bc16f&sv=1)
There are also more utility functions available here.
Last updated