Skip to content

Commit 1ff3a70

Browse files
committed
Burn extensions and cleanup
1 parent b4fbeef commit 1ff3a70

File tree

3 files changed

+199
-3
lines changed

3 files changed

+199
-3
lines changed

Thirdweb/Thirdweb.Extensions/ThirdwebExtensions.cs

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,35 @@ public static async Task<Drop_ClaimCondition> DropERC20_GetActiveClaimCondition(
16201620

16211621
#region DropERC721
16221622

1623+
/// <summary>
1624+
/// Burn a specific ERC721 token with a given token ID.
1625+
/// </summary>
1626+
/// <param name="contract">The contract to interact with.</param>
1627+
/// <param name="wallet">The wallet to use for the transaction.</param>
1628+
/// <param name="tokenId">The ID of the token to burn.</param>
1629+
/// <returns>A task representing the asynchronous operation, with a ThirdwebTransactionReceipt result.</returns>
1630+
/// <exception cref="ArgumentNullException">Thrown when the contract or wallet is null.</exception>
1631+
/// <exception cref="ArgumentOutOfRangeException">Thrown when the token ID is less than 0.</exception>
1632+
public static async Task<ThirdwebTransactionReceipt> DropER721_Burn(this ThirdwebContract contract, IThirdwebWallet wallet, BigInteger tokenId)
1633+
{
1634+
if (contract == null)
1635+
{
1636+
throw new ArgumentNullException(nameof(contract));
1637+
}
1638+
1639+
if (wallet == null)
1640+
{
1641+
throw new ArgumentNullException(nameof(wallet));
1642+
}
1643+
1644+
if (tokenId < 0)
1645+
{
1646+
throw new ArgumentOutOfRangeException(nameof(tokenId), "Token ID must be equal or greater than 0");
1647+
}
1648+
1649+
return await ThirdwebContract.Write(wallet, contract, "burn", 0, tokenId);
1650+
}
1651+
16231652
/// <summary>
16241653
/// Claim a specific quantity of ERC721 tokens for a receiver.
16251654
/// </summary>
@@ -1729,6 +1758,54 @@ public static async Task<Drop_ClaimCondition> DropERC721_GetActiveClaimCondition
17291758

17301759
#region DropERC1155
17311760

1761+
/// <summary>
1762+
/// Burn a specific quantity of ERC1155 tokens for a specific account with given token IDs and amounts to burn.
1763+
/// </summary>
1764+
/// <param name="contract">The contract to interact with.</param>
1765+
/// <param name="wallet">The wallet to use for the transaction.</param>
1766+
/// <param name="account">The address of the account to burn the tokens from.</param>
1767+
/// <param name="tokenIds">The IDs of the tokens to burn.</param>
1768+
/// <param name="amounts">The amounts of tokens to burn.</param>
1769+
/// <returns>A task representing the asynchronous operation, with a ThirdwebTransactionReceipt result.</returns>
1770+
/// <exception cref="ArgumentNullException">Thrown when the contract, wallet, or account is null.</exception>
1771+
/// <exception cref="ArgumentException">Thrown when the account is null or empty, or the token IDs or amounts are null or empty, or the token IDs and amounts have different lengths.</exception>
1772+
/// <exception cref="ArgumentOutOfRangeException">Thrown when the token IDs or amounts have a length less than or equal to 0.</exception>
1773+
/// <exception cref="ArgumentException">Thrown when the token IDs and amounts have different lengths.</exception>
1774+
public static async Task<ThirdwebTransactionReceipt> DropERC1155_BurnBatch(this ThirdwebContract contract, IThirdwebWallet wallet, string account, BigInteger[] tokenIds, BigInteger[] amounts)
1775+
{
1776+
if (contract == null)
1777+
{
1778+
throw new ArgumentNullException(nameof(contract));
1779+
}
1780+
1781+
if (wallet == null)
1782+
{
1783+
throw new ArgumentNullException(nameof(wallet));
1784+
}
1785+
1786+
if (string.IsNullOrEmpty(account))
1787+
{
1788+
throw new ArgumentException("Account must be provided");
1789+
}
1790+
1791+
if (tokenIds == null || tokenIds.Length == 0)
1792+
{
1793+
throw new ArgumentException("Token IDs must be provided");
1794+
}
1795+
1796+
if (amounts == null || amounts.Length == 0)
1797+
{
1798+
throw new ArgumentException("Amounts must be provided");
1799+
}
1800+
1801+
if (tokenIds.Length != amounts.Length)
1802+
{
1803+
throw new ArgumentException("Token IDs and amounts must have the same length");
1804+
}
1805+
1806+
return await ThirdwebContract.Write(wallet, contract, "burnBatch", 0, account, tokenIds, amounts);
1807+
}
1808+
17321809
/// <summary>
17331810
/// Claim a specific quantity of ERC1155 tokens for a receiver.
17341811
/// </summary>
@@ -2026,6 +2103,35 @@ public static async Task<VerifyResult> TokenERC20_VerifyMintSignature(this Third
20262103

20272104
#region TokenERC721
20282105

2106+
/// <summary>
2107+
/// Burn a specific ERC721 token with a given token ID.
2108+
/// </summary>
2109+
/// <param name="contract">The contract to interact with.</param>
2110+
/// <param name="wallet">The wallet to use for the transaction.</param>
2111+
/// <param name="tokenId">The ID of the token to burn.</param>
2112+
/// <returns>A task representing the asynchronous operation, with a ThirdwebTransactionReceipt result.</returns>
2113+
/// <exception cref="ArgumentNullException">Thrown when the contract or wallet is null.</exception>
2114+
/// <exception cref="ArgumentOutOfRangeException">Thrown when the token ID is less than 0.</exception>
2115+
public static async Task<ThirdwebTransactionReceipt> TokenERC721_Burn(this ThirdwebContract contract, IThirdwebWallet wallet, BigInteger tokenId)
2116+
{
2117+
if (contract == null)
2118+
{
2119+
throw new ArgumentNullException(nameof(contract));
2120+
}
2121+
2122+
if (wallet == null)
2123+
{
2124+
throw new ArgumentNullException(nameof(wallet));
2125+
}
2126+
2127+
if (tokenId < 0)
2128+
{
2129+
throw new ArgumentOutOfRangeException(nameof(tokenId), "Token ID must be equal or greater than 0");
2130+
}
2131+
2132+
return await ThirdwebContract.Write(wallet, contract, "burn", 0, tokenId);
2133+
}
2134+
20292135
/// <summary>
20302136
/// Mint a specific ERC721 token to a receiver address with a given URI.
20312137
/// </summary>
@@ -2242,6 +2348,96 @@ public static async Task<VerifyResult> TokenERC721_VerifyMintSignature(this Thir
22422348

22432349
#region TokenERC1155
22442350

2351+
/// <summary>
2352+
/// Burn a specific quantity of ERC1155 tokens for a specific account with a given token ID and amount to burn.
2353+
/// </summary>
2354+
/// <param name="contract">The contract to interact with.</param>
2355+
/// <param name="wallet">The wallet to use for the transaction.</param>
2356+
/// <param name="account">The address of the account to burn the tokens from.</param>
2357+
/// <param name="tokenId">The ID of the token to burn.</param>
2358+
/// <param name="amount">The amount of tokens to burn.</param>
2359+
/// <returns>A task representing the asynchronous operation, with a ThirdwebTransactionReceipt result.</returns>
2360+
/// <exception cref="ArgumentNullException">Thrown when the contract, wallet, or account is null.</exception>
2361+
/// <exception cref="ArgumentException">Thrown when the account is null or empty.</exception>
2362+
/// <exception cref="ArgumentOutOfRangeException">Thrown when the token ID is less than 0 or the amount is less than or equal to 0.</exception>
2363+
public static async Task<ThirdwebTransactionReceipt> TokenERC1155_Burn(this ThirdwebContract contract, IThirdwebWallet wallet, string account, BigInteger tokenId, BigInteger amount)
2364+
{
2365+
if (contract == null)
2366+
{
2367+
throw new ArgumentNullException(nameof(contract));
2368+
}
2369+
2370+
if (wallet == null)
2371+
{
2372+
throw new ArgumentNullException(nameof(wallet));
2373+
}
2374+
2375+
if (string.IsNullOrEmpty(account))
2376+
{
2377+
throw new ArgumentException("Account must be provided");
2378+
}
2379+
2380+
if (tokenId < 0)
2381+
{
2382+
throw new ArgumentOutOfRangeException(nameof(tokenId), "Token ID must be equal or greater than 0");
2383+
}
2384+
2385+
if (amount <= 0)
2386+
{
2387+
throw new ArgumentOutOfRangeException(nameof(amount), "Amount must be greater than 0");
2388+
}
2389+
2390+
return await ThirdwebContract.Write(wallet, contract, "burn", 0, account, tokenId, amount);
2391+
}
2392+
2393+
/// <summary>
2394+
/// Burn a specific quantity of ERC1155 tokens for a specific account with given token IDs and amounts to burn.
2395+
/// </summary>
2396+
/// <param name="contract">The contract to interact with.</param>
2397+
/// <param name="wallet">The wallet to use for the transaction.</param>
2398+
/// <param name="account">The address of the account to burn the tokens from.</param>
2399+
/// <param name="tokenIds">The IDs of the tokens to burn.</param>
2400+
/// <param name="amounts">The amounts of tokens to burn.</param>
2401+
/// <returns>A task representing the asynchronous operation, with a ThirdwebTransactionReceipt result.</returns>
2402+
/// <exception cref="ArgumentNullException">Thrown when the contract, wallet, or account is null.</exception>
2403+
/// <exception cref="ArgumentException">Thrown when the account is null or empty, or the token IDs or amounts are null or empty, or the token IDs and amounts have different lengths.</exception>
2404+
/// <exception cref="ArgumentOutOfRangeException">Thrown when the token IDs or amounts have a length less than or equal to 0.</exception>
2405+
/// <exception cref="ArgumentException">Thrown when the token IDs and amounts have different lengths.</exception>
2406+
public static async Task<ThirdwebTransactionReceipt> TokenERC1155_BurnBatch(this ThirdwebContract contract, IThirdwebWallet wallet, string account, BigInteger[] tokenIds, BigInteger[] amounts)
2407+
{
2408+
if (contract == null)
2409+
{
2410+
throw new ArgumentNullException(nameof(contract));
2411+
}
2412+
2413+
if (wallet == null)
2414+
{
2415+
throw new ArgumentNullException(nameof(wallet));
2416+
}
2417+
2418+
if (string.IsNullOrEmpty(account))
2419+
{
2420+
throw new ArgumentException("Account must be provided");
2421+
}
2422+
2423+
if (tokenIds == null || tokenIds.Length == 0)
2424+
{
2425+
throw new ArgumentException("Token IDs must be provided");
2426+
}
2427+
2428+
if (amounts == null || amounts.Length == 0)
2429+
{
2430+
throw new ArgumentException("Amounts must be provided");
2431+
}
2432+
2433+
if (tokenIds.Length != amounts.Length)
2434+
{
2435+
throw new ArgumentException("Token IDs and amounts must have the same length");
2436+
}
2437+
2438+
return await ThirdwebContract.Write(wallet, contract, "burnBatch", 0, account, tokenIds, amounts);
2439+
}
2440+
22452441
/// <summary>
22462442
/// Mint a specific quantity of ERC1155 tokens to a receiver address with a given URI.
22472443
/// </summary>

Thirdweb/Thirdweb.Wallets/InAppWallet/EcosystemWallet/EcosystemWallet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ public JObject GetUserAuthDetails()
308308
var parts = authToken.Split('.');
309309
if (parts.Length != 3)
310310
{
311-
Console.WriteLine("Invalid JWT");
311+
throw new InvalidOperationException("Invalid JWT");
312312
}
313313

314314
static string Base64UrlDecode(string input)
@@ -335,7 +335,7 @@ static string Base64UrlDecode(string input)
335335
parts = jwtToken.Split('.');
336336
if (parts.Length != 3)
337337
{
338-
Console.WriteLine("Invalid JWT");
338+
throw new InvalidOperationException("Invalid JWT");
339339
}
340340

341341
payload = JObject.Parse(Base64UrlDecode(parts[1]));

Thirdweb/Thirdweb.Wallets/PrivateKeyWallet/PrivateKeyWallet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ public virtual Task<string> SignTransaction(ThirdwebTransactionInput transaction
393393
// (var tx, var sig) = Utils.DecodeTransaction(returnBytes);
394394

395395
signedTransaction = returnBytes.ToHex();
396-
Console.WriteLine(signedTransaction);
396+
// Console.WriteLine(signedTransaction);
397397

398398
// (var tx, var sig) = Utils.DecodeTransaction("0x" + signedTransaction);
399399
}

0 commit comments

Comments
 (0)