Skip to content

Commit 58c3e34

Browse files
generic calls
1 parent c0bf8dd commit 58c3e34

File tree

12 files changed

+217
-30
lines changed

12 files changed

+217
-30
lines changed

.vscode/settings.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"files.exclude":
3+
{
4+
"**/.DS_Store":true,
5+
"**/.git":true,
6+
"**/.gitmodules":true,
7+
"**/*.booproj":true,
8+
"**/*.pidb":true,
9+
"**/*.suo":true,
10+
"**/*.user":true,
11+
"**/*.userprefs":true,
12+
"**/*.unityproj":true,
13+
"**/*.dll":true,
14+
"**/*.exe":true,
15+
"**/*.pdf":true,
16+
"**/*.mid":true,
17+
"**/*.midi":true,
18+
"**/*.wav":true,
19+
"**/*.gif":true,
20+
"**/*.ico":true,
21+
"**/*.jpg":true,
22+
"**/*.jpeg":true,
23+
"**/*.png":true,
24+
"**/*.psd":true,
25+
"**/*.tga":true,
26+
"**/*.tif":true,
27+
"**/*.tiff":true,
28+
"**/*.3ds":true,
29+
"**/*.3DS":true,
30+
"**/*.fbx":true,
31+
"**/*.FBX":true,
32+
"**/*.lxo":true,
33+
"**/*.LXO":true,
34+
"**/*.ma":true,
35+
"**/*.MA":true,
36+
"**/*.obj":true,
37+
"**/*.OBJ":true,
38+
"**/*.asset":true,
39+
"**/*.cubemap":true,
40+
"**/*.flare":true,
41+
"**/*.mat":true,
42+
"**/*.meta":true,
43+
"**/*.prefab":true,
44+
"**/*.unity":true,
45+
"build/":true,
46+
"Build/":true,
47+
"Library/":true,
48+
"library/":true,
49+
"obj/":true,
50+
"Obj/":true,
51+
"ProjectSettings/":true,
52+
"temp/":true,
53+
"Temp/":true
54+
}
55+
}

Assets/Plugin/thirdweb.jslib

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,7 @@ mergeInto(LibraryManager.library, {
1616
dynCall_vii(cb, idPtr, buffer);
1717
});
1818
},
19+
ThirdwebInitialize: function (chain) {
20+
window.bridge.initialize(UTF8ToString(chain));
21+
},
1922
});

Assets/SDKTest.cs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
3-
using System.Threading.Tasks;
41
using UnityEngine;
52
using Thirdweb;
63

74
public class SDKTest : MonoBehaviour
85
{
9-
// Start is called before the first frame update
6+
private ThirdwebSDK sdk;
7+
private Contract contract;
8+
private int count;
109
void Start()
1110
{
12-
11+
this.sdk = new ThirdwebSDK("goerli");
12+
this.contract = sdk.GetContract("0x2e01763fA0e15e07294D74B63cE4b526B321E389");
1313
}
1414

15-
// Update is called once per frame
16-
void Update()
15+
public async void OnButtonClick()
1716
{
18-
19-
}
20-
21-
int count;
22-
23-
public async void OnLoginClick()
24-
{
25-
Debug.Log("Button clicked ");
17+
Debug.Log("Button clicked");
2618
count++;
27-
NFT result = await SDK.GetNFT(count.ToString());
19+
NFT result = await this.contract.ERC721.GetNFT(count.ToString());
2820
Debug.Log("name: " + result.metadata.name);
2921
Debug.Log("owner: " + result.owner);
3022
}

Assets/Scenes/SampleScene.unity

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ MonoBehaviour:
209209
m_Calls:
210210
- m_Target: {fileID: 354401067}
211211
m_TargetAssemblyTypeName: SDKTest, Assembly-CSharp
212-
m_MethodName: OnLoginClick
212+
m_MethodName: OnButtonClick
213213
m_Mode: 1
214214
m_Arguments:
215215
m_ObjectArgument: {fileID: 0}

Assets/Thirdweb/Scripts/Bridge.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ private static void jsCallback(string taskId, string result)
3737
}
3838
}
3939

40+
public static void Initialize(string chainOrRPC) {
41+
ThirdwebInitialize(chainOrRPC);
42+
}
43+
4044
public static async Task<T> InvokeRoute<T>(string route, string[] body)
4145
{
4246
var msg = JsonUtility.ToJson(new RequestMessageBody(body));
@@ -63,5 +67,7 @@ public static async Task<string> InvokeRouteRaw(string route, string[] body)
6367

6468
[DllImport("__Internal")]
6569
private static extern string ThirdwebInvoke(string taskId, string route, string payload, Action<string, string> cb);
70+
[DllImport("__Internal")]
71+
private static extern string ThirdwebInitialize(string chainOrRPC);
6672
}
6773
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
namespace Thirdweb
2+
{
3+
4+
public class Contract
5+
{
6+
public string chain;
7+
public string address;
8+
public ERC721 ERC721;
9+
public Contract(string chain, string address) {
10+
this.chain = chain;
11+
this.address = address;
12+
this.ERC721 = new ERC721(chain, address);
13+
}
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+
// }
45+
}
46+
}
Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.Collections.Generic;
21
using System.Threading.Tasks;
3-
using UnityEngine;
42

53
namespace Thirdweb
64
{
@@ -23,12 +21,22 @@ public struct NFT
2321
public string owner;
2422
}
2523

26-
public class SDK
24+
public class ERC721
2725
{
28-
public static async Task<NFT> GetNFT(string id)
26+
public string chain;
27+
public string address;
28+
public ERC721(string chain, string address)
2929
{
30-
var result = await Bridge.InvokeRoute<NFT>("erc721.get", new string[] { id });
31-
return result;
30+
this.chain = chain;
31+
this.address = address;
32+
}
33+
public async Task<NFT> GetNFT(string id)
34+
{
35+
return await Bridge.InvokeRoute<NFT>(getRoute("get"), new string[] { id });
36+
}
37+
38+
private string getRoute(string functionPath) {
39+
return this.address + ".erc721." + functionPath;
3240
}
3341

3442
// public Currency GetCurrency(string address)

Assets/Thirdweb/Scripts/ERC721.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
namespace Thirdweb
2+
{
3+
4+
public class ThirdwebSDK
5+
{
6+
private string chainOrRPC;
7+
public ThirdwebSDK(string chainOrRPC) {
8+
this.chainOrRPC = chainOrRPC;
9+
Bridge.Initialize(chainOrRPC);
10+
}
11+
12+
public Contract GetContract(string address)
13+
{
14+
return new Contract(this.chainOrRPC, address);
15+
}
16+
// public static async Task<NFT> GetNFT(string id)
17+
// {
18+
// return await Bridge.InvokeRoute<NFT>("erc721.get", new string[] { id });
19+
// }
20+
21+
// public Currency GetCurrency(string address)
22+
// {
23+
// if (!currencyModules.ContainsKey(address))
24+
// {
25+
// currencyModules[address] = new Currency(this, this.bridge, address);
26+
// }
27+
28+
// return currencyModules[address];
29+
// }
30+
31+
// public NFT GetNFT(string address)
32+
// {
33+
// if (!nftModules.ContainsKey(address))
34+
// {
35+
// nftModules[address] = new NFT(this, this.bridge, address);
36+
// }
37+
38+
// return nftModules[address];
39+
// }
40+
41+
// public Market GetMarket(string address)
42+
// {
43+
// if (!marketModules.ContainsKey(address))
44+
// {
45+
// marketModules[address] = new Market(this, this.bridge, address);
46+
// }
47+
48+
// return marketModules[address];
49+
// }
50+
}
51+
}

0 commit comments

Comments
 (0)