The Eidolon Util Class
The Util
class in the Eidolon.Unity SDK provides utility methods for Ethereum-related conversions and handling web requests in Unity WebGL.
Methods
ConvertToWei
Description
This method converts a value from Ether to Wei. This is primarily used for Desktop and Mobile builds and you’ll often use it to convert normal integers into blockchain-ready values.
Example Code
Parameters
value
(BigInteger): A value in Ether.decimals
(optional): The amount of decimals a token has.
Returns
BigInteger
: The value in Wei.
ConvertFromWei
Description
This method converts a value from Wei to Ether.
Example Code
Parameters
value
(BigInteger): A value in Wei.decimals
(optional): The amount of decimals a token has.
Returns
BigDecimal
: The value in Ether.
ConvertBigIntToDecimal
Description
This method converts a BigInteger to a decimal number.
Example Code
Parameters
value
(BigInteger): A value in BigInteger format.decimals
(optional): The amount of decimals you want to divide by.
Returns
decimal
: The value in decimal format.
ConvertStringToHex
Description
This method converts a string value to a hexadecimal string.
Example Code
Parameters
value
(String): A string value.
Returns
string
: A hexadecimal string.
ConvertDecimalToHex
Description
This method converts a decimal value to a hexadecimal string.
Example Code
Parameters
value
(BigInteger): A BigInteger value.
Returns
string
: A hexadecimal string.
ConvertHexToDecimal
Description
This method converts a hex value to a string decimal.
Example Code
Parameters
value
(string): A string hexadecimal value.
Returns
string
: A decimal string.
ConvertHexStringToBigInteger
Description
This method converts a hexadecimal string to a big integer.
Example Code
Parameters
hexString
(string): A hexadecimal string.
Returns
BigInteger
: A big integer.
IsValidEthereumAddress
Description
This method checks if a provided string is a valid Ethereum address in the correct format.
Example Code
Parameters
address
(string): An Ethereum address.
Returns
bool
:true
if the address is valid; otherwise,false
.
ConvertLink
Description
This method converts a given URL to a WebGL-ready URL using a CORS proxy. You can use this method to get around CORS errors when interacting with Web Requests.
Example Code
Parameters
url
(string): The original URL.
Returns
string
: A modified URL that is WebGL-ready.
GetTextureFromURL
Description
This method fetches a Texture2D
from a provided URL and invokes the given callback with the fetched texture. You can use this to fetch NFT images and apply them to in-game objects.
Example Code
Parameters
url
(string): The URL to fetch the texture from.
GetTransactionLogs
Description
This method retrieves the transaction properties from a receipt.
Example Code
Parameters
transactionHash
(string): The hash of the transaction to retrieve.
Returns
Transaction Properties
(FilterLogs): The transaction logs in a list format.
Encode Function Data
Description
This method encodes the data for a provided smart contract function.
Example Code
Parameters
contract
(SmartContract): The smart contractmethodName
(String): The method nameparameters
(object): The method arguments
Returns
- `TransactionInput (String): The transaction input to send off to the blockchain.