Table of Contents

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 BigInteger

The value.

fromDecimals int

The original number of decimals.

toDecimals int

The 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 string

The 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 ThirdwebTransactionReceipt

The transaction receipt.

Returns

List<EventLog<TEventDTO>>

A list of decoded events.

Type Parameters

TEventDTO

The event DTO type.

FetchGasFees(ThirdwebClient, BigInteger, bool)

public static Task<(BigInteger maxFeePerGas, BigInteger maxPriorityFeePerGas)> FetchGasFees(ThirdwebClient client, BigInteger chainId, bool withBump = true)

Parameters

client ThirdwebClient
chainId BigInteger
withBump bool

Returns

Task<(BigInteger maxFeePerGas, BigInteger maxPriorityFeePerGas)>

FetchGasPrice(ThirdwebClient, BigInteger, bool)

public static Task<BigInteger> FetchGasPrice(ThirdwebClient client, BigInteger chainId, bool withBump = true)

Parameters

client ThirdwebClient
chainId BigInteger
withBump bool

Returns

Task<BigInteger>

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 string

The wei value to format.

decimalsToDisplay int

The number of decimals to display.

decimals int

The number of decimals of the token.

addCommas bool

Whether 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 LoginPayloadData

The login payload data.

Returns

string

The generated SIWE message.

GetAddressFromENS(ThirdwebClient, string)

public static Task<string> GetAddressFromENS(ThirdwebClient client, string ensName)

Parameters

client ThirdwebClient
ensName string

Returns

Task<string>

GetChainMetadata(ThirdwebClient, BigInteger)

public static Task<ThirdwebChainData> GetChainMetadata(ThirdwebClient client, BigInteger chainId)

Parameters

client ThirdwebClient
chainId BigInteger

Returns

Task<ThirdwebChainData>

GetENSFromAddress(ThirdwebClient, string)

public static Task<string> GetENSFromAddress(ThirdwebClient client, string address)

Parameters

client ThirdwebClient
address string

Returns

Task<string>

GetEntryPointVersion(string)

public static int GetEntryPointVersion(string address)

Parameters

address string

Returns

int

GetSocialProfiles(ThirdwebClient, string)

Gets the social profiles for the given address or ENS.

public static Task<SocialProfiles> GetSocialProfiles(ThirdwebClient client, string addressOrEns)

Parameters

client ThirdwebClient

The Thirdweb client.

addressOrEns string

The 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 string

The 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 string

The 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.

public static BigInteger HexToBigInt(this string hex)

Parameters

hex string

The 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 string

The hex string to convert.

Returns

byte[]

The bytes.

HexToBytes32(string)

public static byte[] HexToBytes32(this string hex)

Parameters

hex string

Returns

byte[]

HexToString(string)

Converts the given hex string to a regular string.

public static string HexToString(this string hex)

Parameters

hex string

The 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 ThirdwebClient
chainId BigInteger
address string

Returns

Task<bool>

IsEip1559Supported(string)

public static bool IsEip1559Supported(string chainId)

Parameters

chainId string

Returns

bool

IsEip155Enforced(ThirdwebClient, BigInteger)

public static Task<bool> IsEip155Enforced(ThirdwebClient client, BigInteger chainId)

Parameters

client ThirdwebClient
chainId BigInteger

Returns

Task<bool>

IsValidAddress(string)

public static bool IsValidAddress(this string address)

Parameters

address string

Returns

bool

IsZkSync(ThirdwebClient, BigInteger)

Checks if the chain ID corresponds to zkSync.

public static Task<bool> IsZkSync(ThirdwebClient client, BigInteger chainId)

Parameters

client ThirdwebClient

The Thirdweb client.

chainId BigInteger

The chain ID.

Returns

Task<bool>

True if it is a zkSync chain ID, otherwise false.

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 string

The 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 IThirdwebHttpClient
defaultHeaders Dictionary<string, string>

Returns

IThirdwebHttpClient

ReplaceIPFS(string, string)

Replaces the IPFS URI with a specified gateway.

public static string ReplaceIPFS(this string uri, string gateway = null)

Parameters

uri string

The URI to replace.

gateway string

The gateway to use.

Returns

string

The replaced URI.

StringToHex(string)

Converts the given string to a hex string.

public static string StringToHex(this string str)

Parameters

str string

The 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 string

The 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 string

The wei value to convert.

decimalsToDisplay int

The number of decimals to display.

addCommas bool

Whether 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

string

Type Parameters

TMessage
TDomain

ToWei(string)

Converts the given ether value to wei.

public static string ToWei(this string eth)

Parameters

eth string

The ether value to convert.

Returns

string

The wei value.