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
Address
public string Address { get; }
Property Value
Chain
public BigInteger Chain { get; }
Property Value
Client
public ThirdwebClient Client { get; }
Property Value
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
clientThirdwebClientThe Thirdweb client.
addressstringThe contract address.
chainBigIntegerThe chain ID.
abistringThe 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
clientThirdwebClientThe Thirdweb client.
chainIdBigIntegerThe chain ID.
serverWalletAddressstringThe server wallet address.
bytecodestringThe bytecode of the contract.
abistringThe ABI of the contract.
constructorParamsDictionary<string, object>The constructor parameters (optional).
saltstringThe salt for the contract deployment (optional).
cancellationTokenCancellationTokenThe cancellation token.
Returns
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
clientThirdwebClientThe Thirdweb client.
addressstringThe contract address.
chainIdBigIntegerThe chain ID.
Returns
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
walletIThirdwebWalletThe wallet instance.
contractThirdwebContractThe contract instance.
methodstringThe method to call.
weiValueBigIntegerThe value in wei to send.
parametersobject[]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
contractThirdwebContractThe contract instance.
methodstringThe method to call.
parametersobject[]The parameters for the method.
Returns
- Task<T>
The result of the method call.
Type Parameters
TThe 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
walletIThirdwebWalletThe wallet instance.
contractThirdwebContractThe contract instance.
methodstringThe method to call.
weiValueBigIntegerThe value in wei to send.
parametersobject[]The parameters for the method.
Returns
- Task<ThirdwebTransactionReceipt>
A transaction receipt.