Skip to content

Commit 37f1e8b

Browse files
add support for reading claim conditions
1 parent fc5e098 commit 37f1e8b

File tree

5 files changed

+210
-8
lines changed

5 files changed

+210
-8
lines changed

Assets/Thirdweb/Scripts/ERC1155.cs

+53
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ public class ERC1155
1212
public string chain;
1313
public string address;
1414
public ERC1155Signature signature;
15+
public ERC1155ClaimConditions claimConditions;
1516

1617
public ERC1155(string chain, string address)
1718
{
1819
this.chain = chain;
1920
this.address = address;
2021
this.signature = new ERC1155Signature(chain, address);
22+
this.claimConditions = new ERC1155ClaimConditions(chain, address);
2123
}
2224

2325
/// READ FUNCTIONS
@@ -121,6 +123,57 @@ private string getRoute(string functionPath) {
121123
}
122124
}
123125

126+
/// <summary>
127+
/// Fetch claim conditions for a given ERC1155 drop contract
128+
/// </summary>
129+
public class ERC1155ClaimConditions
130+
{
131+
public string chain;
132+
public string address;
133+
134+
public ERC1155ClaimConditions(string chain, string address)
135+
{
136+
this.chain = chain;
137+
this.address = address;
138+
}
139+
140+
/// <summary>
141+
/// Get the active claim condition
142+
/// </summary>
143+
public async Task<ClaimConditions> GetActive(string tokenId)
144+
{
145+
return await Bridge.InvokeRoute<ClaimConditions>(getRoute("getActive"), Utils.ToJsonStringArray(tokenId));
146+
}
147+
148+
/// <summary>
149+
/// Check whether the connected wallet is eligible to claim
150+
/// </summary>
151+
public async Task<bool> CanClaim(string tokenId, int quantity, string addressToCheck = null)
152+
{
153+
return await Bridge.InvokeRoute<bool>(getRoute("canClaim"), Utils.ToJsonStringArray(tokenId, quantity, addressToCheck));
154+
}
155+
156+
/// <summary>
157+
/// Get the reasons why the connected wallet is not eligible to claim
158+
/// </summary>
159+
public async Task<string[]> GetIneligibilityReasons(string tokenId, int quantity, string addressToCheck = null)
160+
{
161+
return await Bridge.InvokeRoute<string[]>(getRoute("getClaimIneligibilityReasons"), Utils.ToJsonStringArray(tokenId, quantity, addressToCheck));
162+
}
163+
164+
/// <summary>
165+
/// Get the special values set in the allowlist for the given wallet
166+
/// </summary>
167+
public async Task<bool> GetClaimerProofs(string tokenId, string claimerAddress)
168+
{
169+
return await Bridge.InvokeRoute<bool>(getRoute("getClaimerProofs"), Utils.ToJsonStringArray(claimerAddress));
170+
}
171+
172+
private string getRoute(string functionPath) {
173+
return this.address + ".erc1155.claimConditions." + functionPath;
174+
}
175+
}
176+
124177
// TODO switch to another JSON serializer that supports polymorphism
125178
[System.Serializable]
126179
#nullable enable

Assets/Thirdweb/Scripts/ERC20.cs

+68-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace Thirdweb
55
{
66
/// <summary>
7-
/// Interact with any <c>ERC20</c> compatible contract.
7+
/// Interact with any ERC20 compatible contract.
88
/// </summary>
99
public class ERC20
1010
{
@@ -14,12 +14,20 @@ public class ERC20
1414
/// Handle signature minting functionality
1515
/// </summary>
1616
public ERC20Signature signature;
17+
/// <summary>
18+
/// Fetch claim conditions for a given ERC20 drop contract
19+
/// </summary>
20+
public ERC20ClaimConditions claimConditions;
1721

22+
/// <summary>
23+
/// Interact with any ERC20 compatible contract.
24+
/// </summary>
1825
public ERC20(string chain, string address)
1926
{
2027
this.chain = chain;
2128
this.address = address;
2229
this.signature = new ERC20Signature(chain, address);
30+
this.claimConditions = new ERC20ClaimConditions(chain, address);
2331
}
2432

2533
// READ FUNCTIONS
@@ -184,11 +192,70 @@ public struct ERC20SignedPayload
184192
public ERC20SignedPayloadOutput payload;
185193
}
186194

195+
/// <summary>
196+
/// Fetch claim conditions for a given ERC20 drop contract
197+
/// </summary>
198+
public class ERC20ClaimConditions
199+
{
200+
public string chain;
201+
public string address;
202+
203+
public ERC20ClaimConditions(string chain, string address)
204+
{
205+
this.chain = chain;
206+
this.address = address;
207+
}
208+
209+
210+
/// <summary>
211+
/// Get the active claim condition
212+
/// </summary>
213+
public async Task<ClaimConditions> GetActive()
214+
{
215+
return await Bridge.InvokeRoute<ClaimConditions>(getRoute("getActive"), new string[] { });
216+
}
217+
218+
/// <summary>
219+
/// Check whether the connected wallet is eligible to claim
220+
/// </summary>
221+
public async Task<bool> CanClaim(string quantity, string? addressToCheck = null)
222+
{
223+
return await Bridge.InvokeRoute<bool>(getRoute("canClaim"), Utils.ToJsonStringArray(quantity, addressToCheck));
224+
}
225+
226+
/// <summary>
227+
/// Get the reasons why the connected wallet is not eligible to claim
228+
/// </summary>
229+
public async Task<string[]> GetIneligibilityReasons(string quantity, string? addressToCheck = null)
230+
{
231+
return await Bridge.InvokeRoute<string[]>(getRoute("getClaimIneligibilityReasons"), Utils.ToJsonStringArray(quantity, addressToCheck));
232+
}
233+
234+
/// <summary>
235+
/// Get the special values set in the allowlist for the given wallet
236+
/// </summary>
237+
public async Task<bool> GetClaimerProofs(string claimerAddress)
238+
{
239+
return await Bridge.InvokeRoute<bool>(getRoute("getClaimerProofs"), Utils.ToJsonStringArray(claimerAddress));
240+
}
241+
242+
private string getRoute(string functionPath) {
243+
return this.address + ".erc20.claimConditions." + functionPath;
244+
}
245+
}
246+
247+
248+
/// <summary>
249+
/// Generate, verify and mint signed mintable payloads
250+
/// </summary>
187251
public class ERC20Signature
188252
{
189253
public string chain;
190254
public string address;
191255

256+
/// <summary>
257+
/// Generate, verify and mint signed mintable payloads
258+
/// </summary>
192259
public ERC20Signature(string chain, string address)
193260
{
194261
this.chain = chain;

Assets/Thirdweb/Scripts/ERC721.cs

+54
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ public class ERC721
1212
public string chain;
1313
public string address;
1414
public ERC721Signature signature;
15+
public ERC721ClaimConditions claimConditions;
1516

1617
public ERC721(string chain, string address)
1718
{
1819
this.chain = chain;
1920
this.address = address;
2021
this.signature = new ERC721Signature(chain, address);
22+
this.claimConditions = new ERC721ClaimConditions(chain, address);
2123
}
2224

2325
/// READ FUNCTIONS
@@ -116,6 +118,58 @@ private string getRoute(string functionPath) {
116118
}
117119
}
118120

121+
/// <summary>
122+
/// Fetch claim conditions for a given ERC721 drop contract
123+
/// </summary>
124+
public class ERC721ClaimConditions
125+
{
126+
public string chain;
127+
public string address;
128+
129+
public ERC721ClaimConditions(string chain, string address)
130+
{
131+
this.chain = chain;
132+
this.address = address;
133+
}
134+
135+
136+
/// <summary>
137+
/// Get the active claim condition
138+
/// </summary>
139+
public async Task<ClaimConditions> GetActive()
140+
{
141+
return await Bridge.InvokeRoute<ClaimConditions>(getRoute("getActive"), new string[] { });
142+
}
143+
144+
/// <summary>
145+
/// Check whether the connected wallet is eligible to claim
146+
/// </summary>
147+
public async Task<bool> CanClaim(int quantity, string addressToCheck = null)
148+
{
149+
return await Bridge.InvokeRoute<bool>(getRoute("canClaim"), Utils.ToJsonStringArray(quantity, addressToCheck));
150+
}
151+
152+
/// <summary>
153+
/// Get the reasons why the connected wallet is not eligible to claim
154+
/// </summary>
155+
public async Task<string[]> GetIneligibilityReasons(int quantity, string addressToCheck = null)
156+
{
157+
return await Bridge.InvokeRoute<string[]>(getRoute("getClaimIneligibilityReasons"), Utils.ToJsonStringArray(quantity, addressToCheck));
158+
}
159+
160+
/// <summary>
161+
/// Get the special values set in the allowlist for the given wallet
162+
/// </summary>
163+
public async Task<bool> GetClaimerProofs(string claimerAddress)
164+
{
165+
return await Bridge.InvokeRoute<bool>(getRoute("getClaimerProofs"), Utils.ToJsonStringArray(claimerAddress));
166+
}
167+
168+
private string getRoute(string functionPath) {
169+
return this.address + ".erc721.claimConditions." + functionPath;
170+
}
171+
}
172+
119173
[System.Serializable]
120174
#nullable enable
121175
public class ERC721MintPayload

Assets/Thirdweb/Scripts/Types.cs

+25-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public struct NFTMetadata
1414
public string image;
1515
public string name;
1616
public string external_url;
17-
public Dictionary<string, string> properties;
17+
public Dictionary<string, object> properties;
1818
}
1919

2020
[System.Serializable]
@@ -141,6 +141,30 @@ public class MarketplaceFilter: QueryAllParams
141141
public string tokenId;
142142
}
143143

144+
// Claim conditions
145+
146+
[System.Serializable]
147+
public class ClaimConditions
148+
{
149+
public string availableSupply;
150+
public string currentMintSupply;
151+
public CurrencyValue currencyMetadata;
152+
public string price;
153+
public string currencyAddress;
154+
public string maxClaimableSupply;
155+
public string maxClaimablePerWallet;
156+
public string waitInSeconds;
157+
}
158+
159+
[System.Serializable]
160+
public class SnapshotEntry
161+
{
162+
public string address;
163+
public string maxClaimable;
164+
public string price;
165+
public string currencyAddress;
166+
}
167+
144168
// Transactions
145169

146170
[System.Serializable]

Assets/ThirdwebSDKDemos.cs

+10-6
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,19 @@ public async void MintERC1155()
128128

129129
// claim
130130
var contract = sdk.GetContract("0x86B7df0dc0A790789D8fDE4C604EF8187FF8AD2A"); // Edition Drop
131-
var result = await contract.ERC1155.Claim("0", 1);
132-
var newSupply = await contract.ERC1155.TotalSupply("0");
133-
if (result[0].isSuccessful()) {
134-
resultText.text = "Claim successful! New supply: " + newSupply;
131+
var canClaim = await contract.ERC1155.claimConditions.CanClaim("0", 1);
132+
if (canClaim) {
133+
var result = await contract.ERC1155.Claim("0", 1);
134+
var newSupply = await contract.ERC1155.TotalSupply("0");
135+
if (result[0].isSuccessful()) {
136+
resultText.text = "Claim successful! New supply: " + newSupply;
137+
} else {
138+
resultText.text = "Claim failed (see console)";
139+
}
135140
} else {
136-
resultText.text = "Claim failed (see console)";
141+
resultText.text = "Can't claim";
137142
}
138143

139-
140144
// sig mint additional supply
141145
// var contract = sdk.GetContract("0xdb9AAb1cB8336CCd50aF8aFd7d75769CD19E5FEc"); // Edition
142146
// var payload = new ERC1155MintAdditionalPayload("0xE79ee09bD47F4F5381dbbACaCff2040f2FbC5803", "1");

0 commit comments

Comments
 (0)