Skip to content

Commit 6224152

Browse files
new JSON lib, gasless support
1 parent 4553e23 commit 6224152

File tree

7 files changed

+31
-44
lines changed

7 files changed

+31
-44
lines changed

Assets/Plugin/thirdweb.jslib

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var plugin = {
1616
dynCall_viii(cb, idPtr, buffer, null);
1717
})
1818
.catch((err) => {
19+
console.error("ThirdwebSDK invoke error", err);
1920
var msg = err.message;
2021
var bufferSize = lengthBytesUTF8(msg) + 1;
2122
var buffer = _malloc(bufferSize);

Assets/SDKTest.cs

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@ public class SDKTest : MonoBehaviour
1111

1212
void Start()
1313
{
14-
sdk = new ThirdwebSDK("goerli", new ThirdwebSDK.Options() {
15-
gasless = new ThirdwebSDK.GaslessOptions() {
16-
openzeppelin = new ThirdwebSDK.OZDefenderOptions() {
17-
relayerUrl = "https://api.defender.openzeppelin.com/autotasks/dad61716-3624-46c9-874f-0e73f15f04d5/runs/webhook/7d6a1834-dd33-4b7b-8af4-b6b4719a0b97/FdHMqyF3p6MGHw6K2nkLsv",
18-
relayerForwarderAddress = "0xEbc1977d1aC2fe1F6DAaF584E2957F7c436fcdEF"
19-
}
20-
}
21-
});
14+
sdk = new ThirdwebSDK("goerli");
2215
}
2316

2417
void Update() {
@@ -72,30 +65,25 @@ public async void GetERC20()
7265

7366
public async void MintERC721()
7467
{
75-
var nftCollection = sdk.GetContract("0x8bFD00BD1D3A2778BDA12AFddE5E65Cca95082DF"); // NFT Collection
68+
var contract = sdk.GetContract("0x2e01763fA0e15e07294D74B63cE4b526B321E389"); // NFT Drop
7669
Debug.Log("Claim button clicked");
7770
//var result = await contract.ERC721.Transfer("0x2247d5d238d0f9d37184d8332aE0289d1aD9991b", count.ToString());
7871
resultText.text = "claiming...";
79-
// var result = await contract.ERC721.Claim(1);
80-
// Debug.Log("result id: " + result[0].id);
81-
// Debug.Log("result receipt: " + result[0].receipt.transactionHash);
82-
// claimButton.text = "claimed tokenId: " + result[0].id;
83-
84-
85-
var meta = new NFTMetadata();
86-
meta.name = "Unity NFT";
87-
meta.description = "Minted From Unity (signature)";
88-
// get a cute kitten image url
89-
meta.image = "ipfs://QmbpciV7R5SSPb6aT9kEBAxoYoXBUsStJkMpxzymV4ZcVc";
72+
var result = await contract.ERC721.Claim(1);
73+
Debug.Log("result id: " + result[0].id);
74+
Debug.Log("result receipt: " + result[0].receipt.transactionHash);
75+
resultText.text = "claimed tokenId: " + result[0].id;
9076

91-
// var result = await nftCollection.ERC721.Mint(meta);
92-
// claimButton.text = "minted tokenId: " + result.id;
93-
9477
// sig mint
95-
var payload = new ERC721MintPayload("0xE79ee09bD47F4F5381dbbACaCff2040f2FbC5803", meta);
96-
var p = await nftCollection.ERC721.signature.Generate(payload);
97-
var result = await nftCollection.ERC721.signature.Mint(p);
98-
resultText.text = "sigminted tokenId: " + result.id;
78+
// var contract = sdk.GetContract("0x8bFD00BD1D3A2778BDA12AFddE5E65Cca95082DF"); // NFT Collection
79+
// var meta = new NFTMetadata();
80+
// meta.name = "Unity NFT";
81+
// meta.description = "Minted From Unity (signature)";
82+
// meta.image = "ipfs://QmbpciV7R5SSPb6aT9kEBAxoYoXBUsStJkMpxzymV4ZcVc";
83+
// var payload = new ERC721MintPayload("0xE79ee09bD47F4F5381dbbACaCff2040f2FbC5803", meta);
84+
// var p = await nftCollection.ERC721.signature.Generate(payload);
85+
// var result = await nftCollection.ERC721.signature.Mint(p);
86+
// resultText.text = "sigminted tokenId: " + result.id;
9987
}
10088

10189
public async void MintERC1155()

Assets/Thirdweb/Scripts/Bridge.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Collections.Generic;
44
using System.Runtime.InteropServices;
55
using System.Threading.Tasks;
6-
using UnityEngine;
6+
using Newtonsoft.Json;
77

88
namespace Thirdweb
99
{
@@ -45,7 +45,7 @@ private static void jsCallback(string taskId, string result, string error)
4545
}
4646

4747
public static void Initialize(string chainOrRPC, ThirdwebSDK.Options options) {
48-
ThirdwebInitialize(chainOrRPC, JsonUtility.ToJson(options));
48+
ThirdwebInitialize(chainOrRPC, Utils.ToJson(options));
4949
}
5050

5151
public static async Task<string> Connect() {
@@ -59,14 +59,14 @@ public static async Task<string> Connect() {
5959

6060
public static async Task<T> InvokeRoute<T>(string route, string[] body)
6161
{
62-
var msg = JsonUtility.ToJson(new RequestMessageBody(body));
62+
var msg = Utils.ToJson(new RequestMessageBody(body));
6363
string taskId = Guid.NewGuid().ToString();
6464
var task = new TaskCompletionSource<string>();
6565
taskMap[taskId] = task;
6666
ThirdwebInvoke(taskId, route, msg, jsCallback);
6767
string result = await task.Task;
6868
// Debug.LogFormat("Result from {0}: {1}", route, result);
69-
return JsonUtility.FromJson<Result<T>>(result).result;
69+
return JsonConvert.DeserializeObject<Result<T>>(result).result;
7070
}
7171

7272
[DllImport("__Internal")]

Assets/Thirdweb/Scripts/ThirdwebSDK.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ public class ThirdwebSDK
1010
[System.Serializable]
1111
public struct Options
1212
{
13-
public GaslessOptions gasless;
13+
public GaslessOptions? gasless;
1414
}
1515

1616
[System.Serializable]
1717
public struct GaslessOptions
1818
{
19-
public OZDefenderOptions openzeppelin;
20-
public BiconomyOptions biconomy;
19+
public OZDefenderOptions? openzeppelin;
20+
public BiconomyOptions? biconomy;
21+
public bool experimentalChainlessSupport;
2122
}
2223

2324
[System.Serializable]

Assets/Thirdweb/Scripts/Utils.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
22
using System.Text;
3-
using UnityEngine;
3+
using Newtonsoft.Json;
44

55
namespace Thirdweb
66
{
@@ -20,12 +20,16 @@ public static string[] ToJsonStringArray(params object[] args) {
2020
}
2121
else
2222
{
23-
stringArgs[i] = JsonUtility.ToJson(args[i]);
23+
stringArgs[i] = Utils.ToJson(args[i]);
2424
}
2525
}
2626
return stringArgs;
2727
}
2828

29+
public static string ToJson(object obj) {
30+
return JsonConvert.SerializeObject(obj, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
31+
}
32+
2933
public static string ToBytes32HexString(byte[] bytes)
3034
{
3135
var hex = new StringBuilder(64);

Packages/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"dependencies": {
3-
"com.unity.nuget.newtonsoft-json": "2.0.0",
3+
"com.unity.nuget.newtonsoft-json": "3.0.1",
44
"com.unity.collab-proxy": "1.17.2",
55
"com.unity.ide.rider": "3.0.15",
66
"com.unity.ide.visualstudio": "2.0.16",

Packages/packages-lock.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
{
22
"dependencies": {
3-
"com.cysharp.unitask": {
4-
"version": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask",
5-
"depth": 0,
6-
"source": "git",
7-
"dependencies": {},
8-
"hash": "b992a061fbf68ff1eb475d0837065b0549ed31ba"
9-
},
103
"com.unity.collab-proxy": {
114
"version": "1.17.2",
125
"depth": 0,

0 commit comments

Comments
 (0)