Class Utils
- Namespace
- Thirdweb
- Assembly
- Thirdweb.dll
Provides utility methods for various operations.
public static class Utils
- Inheritance
-
Utils
- Inherited Members
Methods
AdjustDecimals(BigInteger, int, int)
Adjusts the value's decimals.
public static BigInteger AdjustDecimals(this BigInteger value, int fromDecimals, int toDecimals)
Parameters
value
BigIntegerThe value.
fromDecimals
intThe original number of decimals.
toDecimals
intThe target number of decimals.
Returns
- BigInteger
The value adjusted to the new decimals.
BytesToHex(byte[])
Converts the given bytes to a hex string.
public static string BytesToHex(this byte[] bytes)
Parameters
bytes
byte[]The bytes to convert.
Returns
- string
The hex string.
ComputeClientIdFromSecretKey(string)
Computes the client ID from the given secret key.
public static string ComputeClientIdFromSecretKey(string secretKey)
Parameters
secretKey
stringThe secret key.
Returns
- string
The computed client ID.
DecodeAllEvents<TEventDTO>(ThirdwebTransactionReceipt)
Decodes all events of the specified type from the transaction receipt logs.
public static List<EventLog<TEventDTO>> DecodeAllEvents<TEventDTO>(this ThirdwebTransactionReceipt transactionReceipt) where TEventDTO : new()
Parameters
transactionReceipt
ThirdwebTransactionReceiptThe transaction receipt.
Returns
- List<EventLog<TEventDTO>>
A list of decoded events.
Type Parameters
TEventDTO
The event DTO type.
DecodeAutorizationList(byte[])
Decodes the given RLP-encoded authorization list.
public static List<EIP7702Authorization> DecodeAutorizationList(byte[] authorizationListEncoded)
Parameters
authorizationListEncoded
byte[]
Returns
DecodeTransaction(byte[])
Decodes the given RLP-encoded transaction data.
public static (ThirdwebTransactionInput transactionInput, string signature) DecodeTransaction(byte[] signedRlpData)
Parameters
signedRlpData
byte[]The RLP-encoded signed transaction data.
Returns
- (ThirdwebTransactionInput transactionInput, string signature)
The decoded transaction input and signature.
DecodeTransaction(string)
Decodes the given RLP-encoded transaction data.
public static (ThirdwebTransactionInput transactionInput, string signature) DecodeTransaction(string signedRlpData)
Parameters
signedRlpData
stringThe RLP-encoded signed transaction data.
Returns
- (ThirdwebTransactionInput transactionInput, string signature)
The decoded transaction input and signature.
FetchGasFees(ThirdwebClient, BigInteger, bool)
public static Task<(BigInteger maxFeePerGas, BigInteger maxPriorityFeePerGas)> FetchGasFees(ThirdwebClient client, BigInteger chainId, bool withBump = true)
Parameters
client
ThirdwebClientchainId
BigIntegerwithBump
bool
Returns
FetchGasPrice(ThirdwebClient, BigInteger, bool)
public static Task<BigInteger> FetchGasPrice(ThirdwebClient client, BigInteger chainId, bool withBump = true)
Parameters
client
ThirdwebClientchainId
BigIntegerwithBump
bool
Returns
FormatERC20(string, int, int, bool)
Formats the given ERC20 token value.
public static string FormatERC20(this string wei, int decimalsToDisplay = 4, int decimals = 18, bool addCommas = false)
Parameters
wei
stringThe wei value to format.
decimalsToDisplay
intThe number of decimals to display.
decimals
intThe number of decimals of the token.
addCommas
boolWhether to add commas to the output.
Returns
- string
The formatted token value.
GenerateSIWE(LoginPayloadData)
Generates a Sign-In With Ethereum (SIWE) message.
public static string GenerateSIWE(LoginPayloadData loginPayloadData)
Parameters
loginPayloadData
LoginPayloadDataThe login payload data.
Returns
- string
The generated SIWE message.
GetAddressFromENS(ThirdwebClient, string)
public static Task<string> GetAddressFromENS(ThirdwebClient client, string ensName)
Parameters
client
ThirdwebClientensName
string
Returns
GetChainMetadata(ThirdwebClient, BigInteger)
public static Task<ThirdwebChainData> GetChainMetadata(ThirdwebClient client, BigInteger chainId)
Parameters
client
ThirdwebClientchainId
BigInteger
Returns
GetENSFromAddress(ThirdwebClient, string)
public static Task<string> GetENSFromAddress(ThirdwebClient client, string address)
Parameters
client
ThirdwebClientaddress
string
Returns
GetEntryPointVersion(string)
public static int GetEntryPointVersion(string address)
Parameters
address
string
Returns
GetSocialProfiles(ThirdwebClient, string)
Gets the social profiles for the given address or ENS.
public static Task<SocialProfiles> GetSocialProfiles(ThirdwebClient client, string addressOrEns)
Parameters
client
ThirdwebClientThe Thirdweb client.
addressOrEns
stringThe wallet address or ENS.
Returns
- Task<SocialProfiles>
A SocialProfiles object containing the social profiles.
Exceptions
- ArgumentNullException
Thrown when the address or ENS is null or empty.
- ArgumentException
Thrown when the address or ENS is invalid.
- Exception
Thrown when the social profiles could not be fetched.
GetUnixTimeStampIn10Years()
Gets the Unix timestamp for 10 years from now.
public static long GetUnixTimeStampIn10Years()
Returns
- long
The Unix timestamp for 10 years from now.
GetUnixTimeStampNow()
Gets the current Unix timestamp.
public static long GetUnixTimeStampNow()
Returns
- long
The current Unix timestamp.
HashMessage(byte[])
Hashes the given message bytes.
public static byte[] HashMessage(this byte[] messageBytes)
Parameters
messageBytes
byte[]The message bytes to hash.
Returns
- byte[]
The hashed message bytes.
HashMessage(string)
Hashes the given message.
public static string HashMessage(this string message)
Parameters
message
stringThe message to hash.
Returns
- string
The hashed message.
HashPrefixedMessage(byte[])
Hashes the given message bytes with a prefixed message.
public static byte[] HashPrefixedMessage(this byte[] messageBytes)
Parameters
messageBytes
byte[]The message bytes to hash.
Returns
- byte[]
The hashed message bytes.
HashPrefixedMessage(string)
Hashes the given message with a prefixed message.
public static string HashPrefixedMessage(this string message)
Parameters
message
stringThe message to hash.
Returns
- string
The hashed message.
HexConcat(params string[])
Concatenates the given hex strings.
public static string HexConcat(params string[] hexStrings)
Parameters
hexStrings
string[]The hex strings to concatenate.
Returns
- string
The concatenated hex string.
HexToBigInt(string)
Converts the given hex string to a big integer.
[Obsolete("Use HexToNumber instead.")]
public static BigInteger HexToBigInt(this string hex)
Parameters
hex
stringThe hex string to convert.
Returns
- BigInteger
The big integer.
HexToBytes(string)
Converts the given hex string to bytes.
public static byte[] HexToBytes(this string hex)
Parameters
hex
stringThe hex string to convert.
Returns
- byte[]
The bytes.
HexToBytes32(string)
public static byte[] HexToBytes32(this string hex)
Parameters
hex
string
Returns
- byte[]
HexToNumber(string)
Converts the given hex string to a big integer.
public static BigInteger HexToNumber(this string hex)
Parameters
hex
stringThe hex string to convert.
Returns
- BigInteger
The big integer.
HexToString(string)
Converts the given hex string to a regular string.
public static string HexToString(this string hex)
Parameters
hex
stringThe hex string to convert.
Returns
- string
The regular string.
IsDeployed(ThirdwebClient, BigInteger, string)
public static Task<bool> IsDeployed(ThirdwebClient client, BigInteger chainId, string address)
Parameters
client
ThirdwebClientchainId
BigIntegeraddress
string
Returns
IsEip1559Supported(string)
public static bool IsEip1559Supported(string chainId)
Parameters
chainId
string
Returns
IsEip155Enforced(ThirdwebClient, BigInteger)
public static Task<bool> IsEip155Enforced(ThirdwebClient client, BigInteger chainId)
Parameters
client
ThirdwebClientchainId
BigInteger
Returns
IsValidAddress(string)
public static bool IsValidAddress(this string address)
Parameters
address
string
Returns
IsZkSync(ThirdwebClient, BigInteger)
Checks if the chain ID corresponds to zkSync.
public static Task<bool> IsZkSync(ThirdwebClient client, BigInteger chainId)
Parameters
client
ThirdwebClientThe Thirdweb client.
chainId
BigIntegerThe chain ID.
Returns
NumberToHex(int)
Converts the given integer to a hex string.
public static string NumberToHex(this int number)
Parameters
number
int
Returns
NumberToHex(long)
Converts the given long to a hex string.
public static string NumberToHex(this long number)
Parameters
number
long
Returns
NumberToHex(BigInteger)
Converts the given big integer to a hex string.
public static string NumberToHex(this BigInteger number)
Parameters
number
BigInteger
Returns
PacketToBytes(string)
public static byte[] PacketToBytes(string packet)
Parameters
packet
string
Returns
- byte[]
PreprocessTypedDataJson(string)
Preprocesses the typed data JSON to stringify large numbers.
public static string PreprocessTypedDataJson(string json)
Parameters
json
stringThe typed data JSON.
Returns
- string
The preprocessed typed data JSON.
ReconstructHttpClient(IThirdwebHttpClient, Dictionary<string, string>)
public static IThirdwebHttpClient ReconstructHttpClient(IThirdwebHttpClient httpClient, Dictionary<string, string> defaultHeaders = null)
Parameters
httpClient
IThirdwebHttpClientdefaultHeaders
Dictionary<string, string>
Returns
ReplaceIPFS(string, string)
Replaces the IPFS URI with a specified gateway.
public static string ReplaceIPFS(this string uri, string gateway = null)
Parameters
Returns
- string
The replaced URI.
SerializeErc6492Signature(string, byte[], byte[])
Serializes a signature for use with ERC-6492. The signature must be generated by a signer for an ERC-4337 Account Factory account with counterfactual deployment addresses.
public static string SerializeErc6492Signature(string address, byte[] data, byte[] signature)
Parameters
address
stringThe ERC-4337 Account Factory address
data
byte[]Account deployment calldata (if not deployed) for counterfactual verification
signature
byte[]The original signature
Returns
- string
The serialized signature hex string.
StringToHex(string)
Converts the given string to a hex string.
public static string StringToHex(this string str)
Parameters
str
stringThe string to convert.
Returns
- string
The hex string.
ToChecksumAddress(string)
Converts an Ethereum address to its checksum format.
public static string ToChecksumAddress(this string address)
Parameters
address
stringThe Ethereum address.
Returns
- string
The checksummed Ethereum address.
ToEth(string, int, bool)
Converts the given wei value to ether.
public static string ToEth(this string wei, int decimalsToDisplay = 4, bool addCommas = false)
Parameters
wei
stringThe wei value to convert.
decimalsToDisplay
intThe number of decimals to display.
addCommas
boolWhether to add commas to the output.
Returns
- string
The ether value.
ToJsonExternalWalletFriendly<TMessage, TDomain>(TypedData<TDomain>, TMessage)
public static string ToJsonExternalWalletFriendly<TMessage, TDomain>(TypedData<TDomain> typedData, TMessage message)
Parameters
typedData
TypedData<TDomain>message
TMessage
Returns
Type Parameters
TMessage
TDomain
ToWei(string)
Converts the given ether value to wei.
public static string ToWei(this string eth)
Parameters
eth
stringThe ether value to convert.
Returns
- string
The wei value.
TrimZeroes(byte[])
Removes leading zeroes from the given byte array.
public static byte[] TrimZeroes(this byte[] bytes)
Parameters
bytes
byte[]
Returns
- byte[]