Table of Contents

Class ThirdwebContract

Namespace
Thirdweb
Assembly
Thirdweb.dll

Represents a Thirdweb contract.

public class ThirdwebContract
Inheritance
ThirdwebContract
Inherited Members
Extension Methods

Properties

Abi

public string Abi { get; }

Property Value

string

Address

public string Address { get; }

Property Value

string

Chain

public BigInteger Chain { get; }

Property Value

BigInteger

Client

public ThirdwebClient Client { get; }

Property Value

ThirdwebClient

Methods

Create(ThirdwebClient, string, BigInteger, string)

Creates a new instance of ThirdwebContract.

public static Task<ThirdwebContract> Create(ThirdwebClient client, string address, BigInteger chain, string abi = null)

Parameters

client ThirdwebClient

The Thirdweb client.

address string

The contract address.

chain BigInteger

The chain ID.

abi string

The contract ABI (optional).

Returns

Task<ThirdwebContract>

A new instance of ThirdwebContract.

Exceptions

ArgumentException

Thrown if any of the required parameters are missing.

Deploy(ThirdwebClient, BigInteger, string, string, string, Dictionary<string, object>, string, CancellationToken)

Deploys a new contract on the specified chain.

public static Task<string> Deploy(ThirdwebClient client, BigInteger chainId, string serverWalletAddress, string bytecode, string abi, Dictionary<string, object> constructorParams = null, string salt = null, CancellationToken cancellationToken = default)

Parameters

client ThirdwebClient

The Thirdweb client.

chainId BigInteger

The chain ID.

serverWalletAddress string

The server wallet address.

bytecode string

The bytecode of the contract.

abi string

The ABI of the contract.

constructorParams Dictionary<string, object>

The constructor parameters (optional).

salt string

The salt for the contract deployment (optional).

cancellationToken CancellationToken

The cancellation token.

Returns

Task<string>

The contract address of the fully deployed contract.

Remarks

This method deploys a new contract using a server wallet, create one via the ServerWallet class or api.thirdweb.com, or the dashboard.

Exceptions

ArgumentNullException

Thrown if any of the required parameters are null.

ArgumentException

Thrown if any of the required parameters are invalid.

OverflowException

Thrown if the chain ID is too large.

InvalidOperationException

Thrown if the deployment fails or the API response is invalid.

JsonException

Thrown if the ABI JSON cannot be parsed.

FetchAbi(ThirdwebClient, string, BigInteger)

Fetches the ABI for the specified contract.

public static Task<string> FetchAbi(ThirdwebClient client, string address, BigInteger chainId)

Parameters

client ThirdwebClient

The Thirdweb client.

address string

The contract address.

chainId BigInteger

The chain ID.

Returns

Task<string>

The contract ABI.

Prepare(IThirdwebWallet, ThirdwebContract, string, BigInteger, params object[])

Prepares a transaction for the specified method and parameters.

public static Task<ThirdwebTransaction> Prepare(IThirdwebWallet wallet, ThirdwebContract contract, string method, BigInteger weiValue, params object[] parameters)

Parameters

wallet IThirdwebWallet

The wallet instance.

contract ThirdwebContract

The contract instance.

method string

The method to call.

weiValue BigInteger

The value in wei to send.

parameters object[]

The parameters for the method.

Returns

Task<ThirdwebTransaction>

A prepared transaction.

Read<T>(ThirdwebContract, string, params object[])

Reads data from the contract using the specified method.

public static Task<T> Read<T>(ThirdwebContract contract, string method, params object[] parameters)

Parameters

contract ThirdwebContract

The contract instance.

method string

The method to call.

parameters object[]

The parameters for the method.

Returns

Task<T>

The result of the method call.

Type Parameters

T

The type of the return value.

Write(IThirdwebWallet, ThirdwebContract, string, BigInteger, params object[])

Writes data to the contract using the specified method and parameters.

public static Task<ThirdwebTransactionReceipt> Write(IThirdwebWallet wallet, ThirdwebContract contract, string method, BigInteger weiValue, params object[] parameters)

Parameters

wallet IThirdwebWallet

The wallet instance.

contract ThirdwebContract

The contract instance.

method string

The method to call.

weiValue BigInteger

The value in wei to send.

parameters object[]

The parameters for the method.

Returns

Task<ThirdwebTransactionReceipt>

A transaction receipt.