Skip to content

Commit 5d1b00d

Browse files
add all erc721 functions
1 parent aeed2d5 commit 5d1b00d

File tree

4 files changed

+80
-33
lines changed

4 files changed

+80
-33
lines changed

Assets/SDKTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ public async void OnButtonClick()
3434
Debug.Log("Button clicked");
3535
count++;
3636
fetchButton.text = "Fetching Token: " + count;
37-
NFT result = await contract.ERC721.GetNFT(count.ToString());
37+
NFT result = await contract.ERC721.Get(count.ToString());
3838
Debug.Log("name: " + result.metadata.name);
3939
Debug.Log("owner: " + result.owner);
4040
fetchButton.text = result.metadata.name;
41+
// int supply = await contract.ERC721.TotalClaimedSupply();
42+
// fetchButton.text = supply.ToString();
4143
}
4244

4345
public async void OnWriteButtonClick()
Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
namespace Thirdweb
22
{
33

4+
/// <summary>
5+
/// Convenient wrapper to interact with any EVM contract
6+
/// </summary>
47
public class Contract
58
{
69
public string chain;
@@ -11,36 +14,5 @@ public Contract(string chain, string address) {
1114
this.address = address;
1215
this.ERC721 = new ERC721(chain, address);
1316
}
14-
15-
16-
// public Currency GetCurrency(string address)
17-
// {
18-
// if (!currencyModules.ContainsKey(address))
19-
// {
20-
// currencyModules[address] = new Currency(this, this.bridge, address);
21-
// }
22-
23-
// return currencyModules[address];
24-
// }
25-
26-
// public NFT GetNFT(string address)
27-
// {
28-
// if (!nftModules.ContainsKey(address))
29-
// {
30-
// nftModules[address] = new NFT(this, this.bridge, address);
31-
// }
32-
33-
// return nftModules[address];
34-
// }
35-
36-
// public Market GetMarket(string address)
37-
// {
38-
// if (!marketModules.ContainsKey(address))
39-
// {
40-
// marketModules[address] = new Market(this, this.bridge, address);
41-
// }
42-
43-
// return marketModules[address];
44-
// }
4517
}
4618
}

Assets/Thirdweb/Scripts/ERC721.cs

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public struct TransactionResult
3939
public string id;
4040
}
4141

42+
/// <summary>
43+
/// Interact with any <c>ERC721</c> compatible contract.
44+
/// </summary>
4245
public class ERC721
4346
{
4447
public string chain;
@@ -48,20 +51,87 @@ public ERC721(string chain, string address)
4851
this.chain = chain;
4952
this.address = address;
5053
}
51-
public async Task<NFT> GetNFT(string tokenId)
54+
55+
/// READ FUNCTIONS
56+
57+
58+
public async Task<NFT> Get(string tokenId)
5259
{
5360
return await Bridge.InvokeRoute<NFT>(getRoute("get"), new string[] { tokenId });
5461
}
62+
63+
public async Task<NFT[]> GetAll()
64+
{
65+
return await Bridge.InvokeRoute<NFT[]>(getRoute("getAll"), new string[] { });
66+
}
67+
68+
public async Task<NFT[]> GetOwned()
69+
{
70+
return await Bridge.InvokeRoute<NFT[]>(getRoute("getOwned"), new string[] { });
71+
}
72+
73+
public async Task<NFT[]> GetOwned(string address)
74+
{
75+
return await Bridge.InvokeRoute<NFT[]>(getRoute("getOwned"), new string[] { address });
76+
}
77+
78+
public async Task<string> OwnerOf(string tokenId)
79+
{
80+
return await Bridge.InvokeRoute<string>(getRoute("ownerOf"), new string[] { tokenId });
81+
}
82+
83+
public async Task<string> Balance()
84+
{
85+
return await Bridge.InvokeRoute<string>(getRoute("balance"), new string[] { });
86+
}
87+
88+
public async Task<string> BalancOf(string address)
89+
{
90+
return await Bridge.InvokeRoute<string>(getRoute("balanceOf"), new string[] { address });
91+
}
92+
93+
public async Task<string> IsApprovedForAll(string address, string approvedContract)
94+
{
95+
return await Bridge.InvokeRoute<string>(getRoute("isApproved"), new string[] { address, approvedContract });
96+
}
97+
98+
public async Task<int> TotalClaimedSupply()
99+
{
100+
return await Bridge.InvokeRoute<int>(getRoute("totalClaimedSupply"), new string[] { });
101+
}
102+
103+
public async Task<int> TotalUnclaimedSupply()
104+
{
105+
return await Bridge.InvokeRoute<int>(getRoute("totalUnclaimedSupply"), new string[] { });
106+
}
107+
108+
/// WRITE FUNCTIONS
109+
110+
public async Task<TransactionResult> SetApprovalForAll(string contractToApprove, bool approved)
111+
{
112+
return await Bridge.InvokeRoute<TransactionResult>(getRoute("isApproved"), new string[] { contractToApprove, approved.ToString() });
113+
}
114+
55115
public async Task<TransactionResult> Transfer(string to, string tokenId)
56116
{
57117
return await Bridge.InvokeRoute<TransactionResult>(getRoute("transfer"), new string[] { to, tokenId });
58118
}
59119

120+
public async Task<TransactionResult> Burn( string tokenId)
121+
{
122+
return await Bridge.InvokeRoute<TransactionResult>(getRoute("burn"), new string[] { tokenId });
123+
}
124+
60125
public async Task<TransactionResult[]> Claim(int quantity)
61126
{
62127
return await Bridge.InvokeRoute<TransactionResult[]>(getRoute("claim"), new string[] { quantity.ToString() });
63128
}
64129

130+
public async Task<TransactionResult[]> ClaimTo(string address, int quantity)
131+
{
132+
return await Bridge.InvokeRoute<TransactionResult[]>(getRoute("claimTo"), new string[] { address, quantity.ToString() });
133+
}
134+
65135
private string getRoute(string functionPath) {
66136
return this.address + ".erc721." + functionPath;
67137
}

Assets/Thirdweb/Scripts/ThirdwebSDK.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
namespace Thirdweb
44
{
55

6+
/// <summary>
7+
/// The entry point for the thirdweb SDK.
8+
/// </summary>
69
public class ThirdwebSDK
710
{
811
private string chainOrRPC;

0 commit comments

Comments
 (0)