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
valueBigIntegerThe value.
fromDecimalsintThe original number of decimals.
toDecimalsintThe target number of decimals.
Returns
- BigInteger
The value adjusted to the new decimals.
BytesToHex(byte[], bool)
Converts the given bytes to a hex string.
public static string BytesToHex(this byte[] bytes, bool addPrefix = true)
Parameters
Returns
- string
The hex string.
ComputeClientIdFromSecretKey(string)
Computes the client ID from the given secret key.
public static string ComputeClientIdFromSecretKey(string secretKey)
Parameters
secretKeystringThe secret key.
Returns
- string
The computed client ID.
FetchGasFees(ThirdwebClient, BigInteger, bool)
public static Task<(BigInteger maxFeePerGas, BigInteger maxPriorityFeePerGas)> FetchGasFees(ThirdwebClient client, BigInteger chainId, bool withBump = true)
Parameters
clientThirdwebClientchainIdBigIntegerwithBumpbool
Returns
FetchGasPrice(ThirdwebClient, BigInteger, bool)
public static Task<BigInteger> FetchGasPrice(ThirdwebClient client, BigInteger chainId, bool withBump = true)
Parameters
clientThirdwebClientchainIdBigIntegerwithBumpbool
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
weistringThe wei value to format.
decimalsToDisplayintThe number of decimals to display.
decimalsintThe number of decimals of the token.
addCommasboolWhether 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
loginPayloadDataLoginPayloadDataThe login payload data.
Returns
- string
The generated SIWE message.
GetAddressFromENS(ThirdwebClient, string)
public static Task<string> GetAddressFromENS(ThirdwebClient client, string ensName)
Parameters
clientThirdwebClientensNamestring
Returns
GetChainMetadata(ThirdwebClient, BigInteger)
public static Task<ThirdwebChainData> GetChainMetadata(ThirdwebClient client, BigInteger chainId)
Parameters
clientThirdwebClientchainIdBigInteger
Returns
GetENSFromAddress(ThirdwebClient, string)
public static Task<string> GetENSFromAddress(ThirdwebClient client, string address)
Parameters
clientThirdwebClientaddressstring
Returns
GetEntryPointVersion(string)
public static int GetEntryPointVersion(string address)
Parameters
addressstring
Returns
GetSocialProfiles(ThirdwebClient, string)
Gets the social profiles for the given address or ENS.
public static Task<SocialProfiles> GetSocialProfiles(ThirdwebClient client, string addressOrEns)
Parameters
clientThirdwebClientThe Thirdweb client.
addressOrEnsstringThe 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
messageBytesbyte[]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
messagestringThe 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
messageBytesbyte[]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
messagestringThe message to hash.
Returns
- string
The hashed message.
HexConcat(params string[])
Concatenates the given hex strings.
public static string HexConcat(params string[] hexStrings)
Parameters
hexStringsstring[]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
hexstringThe 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
hexstringThe hex string to convert.
Returns
- byte[]
The bytes.
HexToBytes32(string)
public static byte[] HexToBytes32(this string hex)
Parameters
hexstring
Returns
- byte[]
HexToNumber(string)
Converts the given hex string to a big integer.
public static BigInteger HexToNumber(this string hex)
Parameters
hexstringThe 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
hexstringThe hex string to convert.
Returns
- string
The regular string.
IsDelegatedAccount(ThirdwebClient, BigInteger, string, string)
public static Task<bool> IsDelegatedAccount(ThirdwebClient client, BigInteger chainId, string address, string delegationContract)
Parameters
clientThirdwebClientchainIdBigIntegeraddressstringdelegationContractstring
Returns
IsDeployed(ThirdwebClient, BigInteger, string)
public static Task<bool> IsDeployed(ThirdwebClient client, BigInteger chainId, string address)
Parameters
clientThirdwebClientchainIdBigIntegeraddressstring
Returns
IsEip1559Supported(string)
public static bool IsEip1559Supported(string chainId)
Parameters
chainIdstring
Returns
IsEip155Enforced(ThirdwebClient, BigInteger)
public static Task<bool> IsEip155Enforced(ThirdwebClient client, BigInteger chainId)
Parameters
clientThirdwebClientchainIdBigInteger
Returns
IsValidAddress(string)
public static bool IsValidAddress(this string address)
Parameters
addressstring
Returns
IsZkSync(ThirdwebClient, BigInteger)
Checks if the chain ID corresponds to zkSync.
public static Task<bool> IsZkSync(ThirdwebClient client, BigInteger chainId)
Parameters
clientThirdwebClientThe Thirdweb client.
chainIdBigIntegerThe chain ID.
Returns
NumberToHex(int)
Converts the given integer to a hex string.
public static string NumberToHex(this int number)
Parameters
numberint
Returns
NumberToHex(long)
Converts the given long to a hex string.
public static string NumberToHex(this long number)
Parameters
numberlong
Returns
NumberToHex(BigInteger)
Converts the given big integer to a hex string.
public static string NumberToHex(this BigInteger number)
Parameters
numberBigInteger
Returns
PacketToBytes(string)
public static byte[] PacketToBytes(string packet)
Parameters
packetstring
Returns
- byte[]
PreprocessTypedDataJson(string)
Preprocesses the typed data JSON to stringify large numbers.
public static string PreprocessTypedDataJson(string json)
Parameters
jsonstringThe 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
httpClientIThirdwebHttpClientdefaultHeadersDictionary<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
addressstringThe ERC-4337 Account Factory address
databyte[]Account deployment calldata (if not deployed) for counterfactual verification
signaturebyte[]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
strstringThe 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
addressstringThe 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
weistringThe wei value to convert.
decimalsToDisplayintThe number of decimals to display.
addCommasboolWhether 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
typedDataTypedData<TDomain>messageTMessage
Returns
Type Parameters
TMessageTDomain
ToWei(string)
Converts the given ether value to wei.
public static string ToWei(this string eth)
Parameters
ethstringThe ether value to convert.
Returns
- string
The wei value.
TrackConnection(IThirdwebWallet)
public static void TrackConnection(IThirdwebWallet wallet)
Parameters
walletIThirdwebWallet
TrackTransaction(ThirdwebTransaction, string)
public static void TrackTransaction(ThirdwebTransaction transaction, string transactionHash)
Parameters
transactionThirdwebTransactiontransactionHashstring
TrimZeroes(byte[])
Removes leading zeroes from the given byte array.
public static byte[] TrimZeroes(this byte[] bytes)
Parameters
bytesbyte[]
Returns
- byte[]
WaitForTransactionReceipt(ThirdwebClient, BigInteger, string, CancellationToken)
Waits for the transaction receipt.
public static Task<ThirdwebTransactionReceipt> WaitForTransactionReceipt(ThirdwebClient client, BigInteger chainId, string txHash, CancellationToken cancellationToken = default)
Parameters
clientThirdwebClientThe Thirdweb client.
chainIdBigIntegerThe chain ID.
txHashstringThe transaction hash.
cancellationTokenCancellationTokenThe cancellation token.
Returns
- Task<ThirdwebTransactionReceipt>
The transaction receipt.