Skip to content

Commit dd15656

Browse files
working sig mint
1 parent 87c684b commit dd15656

File tree

6 files changed

+123
-48
lines changed

6 files changed

+123
-48
lines changed

Assets/SDKTest.cs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,28 +74,41 @@ public async void MintERC721()
7474
meta.name = "Unity NFT";
7575
meta.description = "Minted From Unity (signature)";
7676
// get a cute kitten image url
77-
meta.image = "https://placekitten.com/200/300";
77+
meta.image = "ipfs://QmbpciV7R5SSPb6aT9kEBAxoYoXBUsStJkMpxzymV4ZcVc";
7878

7979
// var result = await nftCollection.ERC721.Mint(meta);
8080
// claimButton.text = "minted tokenId: " + result.id;
8181

82-
var payload = new ERC721MintPayload();
83-
payload.metadata = meta;
84-
payload.to = "0xE79ee09bD47F4F5381dbbACaCff2040f2FbC5803";
85-
// TODO allow passing dates as unix timestamps
82+
// sig mint
83+
var payload = new ERC721MintPayload("0xE79ee09bD47F4F5381dbbACaCff2040f2FbC5803", meta);
8684
var p = await nftCollection.ERC721.signature.Generate(payload);
87-
Debug.Log("sig:" + p.signature);
8885
var result = await nftCollection.ERC721.signature.Mint(p);
8986
resultText.text = "sigminted tokenId: " + result.id;
9087
}
9188

9289
public async void MintERC1155()
9390
{
94-
var contract = sdk.GetContract("0x86B7df0dc0A790789D8fDE4C604EF8187FF8AD2A"); // Edition Drop
9591
Debug.Log("Claim button clicked");
9692
resultText.text = "claiming...";
97-
var result = await contract.ERC1155.Claim("0", 1);
98-
Debug.Log("result receipt: " + result[0].receipt.transactionHash);
99-
resultText.text = "claim successful";
93+
94+
// claim
95+
// var contract = sdk.GetContract("0x86B7df0dc0A790789D8fDE4C604EF8187FF8AD2A"); // Edition Drop
96+
// var result = await contract.ERC1155.Claim("0", 1);
97+
// Debug.Log("result receipt: " + result[0].receipt.transactionHash);
98+
// resultText.text = "claim successful";
99+
100+
101+
// sig mint
102+
var contract = sdk.GetContract("0xdb9AAb1cB8336CCd50aF8aFd7d75769CD19E5FEc"); // Edition
103+
// var meta = new NFTMetadata();
104+
// meta.name = "Kitten Unity NFT";
105+
// meta.description = "Cat Minted From Unity (with signature)";
106+
// meta.image = "ipfs://QmbpciV7R5SSPb6aT9kEBAxoYoXBUsStJkMpxzymV4ZcVc";
107+
// var payload = new ERC1155MintPayload(meta);
108+
var payload = new ERC1155MintAdditionalPayload("0xE79ee09bD47F4F5381dbbACaCff2040f2FbC5803", "1");
109+
payload.quantity = 3;
110+
var p = await contract.ERC1155.signature.GenerateFromTokenId(payload);
111+
var result = await contract.ERC1155.signature.Mint(p);
112+
resultText.text = "sigminted tokenId: " + result.id;
100113
}
101114
}

Assets/Scenes/SampleScene.unity

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -844,17 +844,17 @@ RectTransform:
844844
m_GameObject: {fileID: 545609468}
845845
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
846846
m_LocalPosition: {x: 0, y: 0, z: 0}
847-
m_LocalScale: {x: 0.2, y: 0.2, z: 0}
848-
m_ConstrainProportionsScale: 0
847+
m_LocalScale: {x: 0.15, y: 0.15, z: 0}
848+
m_ConstrainProportionsScale: 1
849849
m_Children:
850850
- {fileID: 1562687355}
851851
m_Father: {fileID: 223974230}
852852
m_RootOrder: 7
853853
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
854854
m_AnchorMin: {x: 0, y: 0}
855855
m_AnchorMax: {x: 1, y: 1}
856-
m_AnchoredPosition: {x: 0, y: -200}
857-
m_SizeDelta: {x: 0, y: -400}
856+
m_AnchoredPosition: {x: 0, y: -300}
857+
m_SizeDelta: {x: 0, y: -600}
858858
m_Pivot: {x: 0.5, y: 0.5}
859859
--- !u!114 &545609470
860860
MonoBehaviour:
@@ -1843,7 +1843,7 @@ RectTransform:
18431843
m_GameObject: {fileID: 1562687354}
18441844
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
18451845
m_LocalPosition: {x: 0, y: 0, z: 0}
1846-
m_LocalScale: {x: 1, y: 1, z: 1}
1846+
m_LocalScale: {x: 2, y: 2, z: 1}
18471847
m_ConstrainProportionsScale: 0
18481848
m_Children: []
18491849
m_Father: {fileID: 545609469}
@@ -1903,8 +1903,8 @@ MonoBehaviour:
19031903
m_faceColor:
19041904
serializedVersion: 2
19051905
rgba: 4294967295
1906-
m_fontSize: 100
1907-
m_fontSizeBase: 100
1906+
m_fontSize: 120
1907+
m_fontSizeBase: 120
19081908
m_fontWeight: 400
19091909
m_enableAutoSizing: 0
19101910
m_fontSizeMin: 18

Assets/Thirdweb/Scripts/Bridge.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ private static void jsCallback(string taskId, string result, string error)
3434
{
3535
if (error != null)
3636
{
37-
taskMap[taskId].SetException(new Exception(error));
37+
// TODO wrap error in proper result type
38+
taskMap[taskId].TrySetException(new Exception(error));
3839
} else
3940
{
40-
taskMap[taskId].SetResult(result);
41+
taskMap[taskId].TrySetResult(result);
4142
}
4243
taskMap.Remove(taskId);
4344
}

Assets/Thirdweb/Scripts/ERC1155.cs

Lines changed: 63 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,42 @@ private string getRoute(string functionPath) {
120120
}
121121
}
122122

123+
// TODO switch to another JSON serializer that supports polymorphism
123124
[System.Serializable]
124125
#nullable enable
125126
public class ERC1155MintPayload
127+
{
128+
public string to;
129+
public string price;
130+
public string currencyAddress;
131+
public string primarySaleRecipient;
132+
public string royaltyRecipient;
133+
public int royaltyBps;
134+
public int quantity;
135+
public NFTMetadata metadata;
136+
public string uid;
137+
// TODO implement these, needs JS bridging support
138+
// public long mintStartTime;
139+
// public long mintEndTime;
140+
141+
public ERC1155MintPayload(string receiverAddress, NFTMetadata metadata) {
142+
this.metadata = metadata;
143+
this.to = receiverAddress;
144+
this.price = "0";
145+
this.currencyAddress = Utils.AddressZero;
146+
this.primarySaleRecipient = Utils.AddressZero;
147+
this.royaltyRecipient = Utils.AddressZero;
148+
this.royaltyBps = 0;
149+
this.quantity = 1;
150+
this.uid = Utils.ToBytes32HexString(Guid.NewGuid().ToByteArray());
151+
// TODO temporary solution
152+
// this.mintStartTime = Utils.UnixTimeNowMs() * 1000L;
153+
// this.mintEndTime = this.mintStartTime + 1000L * 60L * 60L * 24L * 365L;
154+
}
155+
}
156+
157+
[System.Serializable]
158+
public class ERC1155MintAdditionalPayload
126159
{
127160
public string tokenId;
128161
public string to;
@@ -132,34 +165,49 @@ public class ERC1155MintPayload
132165
public string royaltyRecipient;
133166
public int royaltyBps;
134167
public int quantity;
135-
public NFTMetadata? metadata;
136168
public string uid;
137169
// TODO implement these, needs JS bridging support
138-
public long mintStartTime;
139-
public long mintEndTime;
170+
// public long mintStartTime;
171+
// public long mintEndTime;
140172

141-
public ERC1155MintPayload() {
142-
this.tokenId = ""; // TODO max uint256 by default
143-
this.to = Utils.AddressZero;
173+
public ERC1155MintAdditionalPayload(string receiverAddress, string tokenId) {
174+
this.tokenId = tokenId;
175+
this.to = receiverAddress;
144176
this.price = "0";
145177
this.currencyAddress = Utils.AddressZero;
146178
this.primarySaleRecipient = Utils.AddressZero;
147179
this.royaltyRecipient = Utils.AddressZero;
148180
this.royaltyBps = 0;
149181
this.quantity = 1;
150-
this.metadata = null;
151182
this.uid = Utils.ToBytes32HexString(Guid.NewGuid().ToByteArray());
152183
// TODO temporary solution
153-
this.mintStartTime = Utils.UnixTimeNowMs() * 1000L;
154-
this.mintEndTime = this.mintStartTime + 1000L * 60L * 60L * 24L * 365L;
184+
// this.mintStartTime = Utils.UnixTimeNowMs() * 1000L;
185+
// this.mintEndTime = this.mintStartTime + 1000L * 60L * 60L * 24L * 365L;
155186
}
156187
}
157188

189+
[System.Serializable]
190+
public struct ERC1155SignedPayloadOutput
191+
{
192+
public string to;
193+
public string tokenId;
194+
public string price;
195+
public string currencyAddress;
196+
public string primarySaleRecipient;
197+
public string royaltyRecipient;
198+
public int royaltyBps;
199+
public int quantity;
200+
public string uri;
201+
public string uid;
202+
public long mintStartTime;
203+
public long mintEndTime;
204+
}
205+
158206
[System.Serializable]
159207
public struct ERC1155SignedPayload
160208
{
161209
public string signature;
162-
public ERC1155MintPayload payload;
210+
public ERC1155SignedPayloadOutput payload;
163211
}
164212

165213
public class ERC1155Signature
@@ -178,6 +226,11 @@ public async Task<ERC1155SignedPayload> Generate(ERC1155MintPayload payloadToSig
178226
return await Bridge.InvokeRoute<ERC1155SignedPayload>(getRoute("generate"), Utils.ToJsonStringArray(payloadToSign));
179227
}
180228

229+
public async Task<ERC1155SignedPayload> GenerateFromTokenId(ERC1155MintAdditionalPayload payloadToSign)
230+
{
231+
return await Bridge.InvokeRoute<ERC1155SignedPayload>(getRoute("generateFromTokenId"), Utils.ToJsonStringArray(payloadToSign));
232+
}
233+
181234
public async Task<bool> Verify(ERC1155SignedPayload signedPayload)
182235
{
183236
return await Bridge.InvokeRoute<bool>(getRoute("verify"), Utils.ToJsonStringArray(signedPayload));

Assets/Thirdweb/Scripts/ERC721.cs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,33 +126,49 @@ public class ERC721MintPayload
126126
public string royaltyRecipient;
127127
public int royaltyBps;
128128
public int quantity;
129-
public NFTMetadata? metadata;
129+
public NFTMetadata metadata;
130130
public string uid;
131131
// TODO implement these, needs JS bridging support
132-
public long mintStartTime;
133-
public long mintEndTime;
132+
// public long mintStartTime;
133+
// public long mintEndTime;
134134

135-
public ERC721MintPayload() {
136-
this.to = Utils.AddressZero;
135+
public ERC721MintPayload(string receiverAddress, NFTMetadata metadata) {
136+
this.metadata = metadata;
137+
this.to = receiverAddress;
137138
this.price = "0";
138139
this.currencyAddress = Utils.AddressZero;
139140
this.primarySaleRecipient = Utils.AddressZero;
140141
this.royaltyRecipient = Utils.AddressZero;
141142
this.royaltyBps = 0;
142143
this.quantity = 1;
143-
this.metadata = null;
144144
this.uid = Utils.ToBytes32HexString(Guid.NewGuid().ToByteArray());
145145
// TODO temporary solution
146-
this.mintStartTime = Utils.UnixTimeNowMs() * 1000L;
147-
this.mintEndTime = this.mintStartTime + 1000L * 60L * 60L * 24L * 365L;
146+
// this.mintStartTime = Utils.UnixTimeNowMs() * 1000L;
147+
// this.mintEndTime = this.mintStartTime + 1000L * 60L * 60L * 24L * 365L;
148148
}
149149
}
150150

151+
[System.Serializable]
152+
public struct ERC721SignedPayloadOutput
153+
{
154+
public string to;
155+
public string price;
156+
public string currencyAddress;
157+
public string primarySaleRecipient;
158+
public string royaltyRecipient;
159+
public int royaltyBps;
160+
public int quantity;
161+
public string uri;
162+
public string uid;
163+
public long mintStartTime;
164+
public long mintEndTime;
165+
}
166+
151167
[System.Serializable]
152168
public struct ERC721SignedPayload
153169
{
154170
public string signature;
155-
public ERC721MintPayload payload;
171+
public ERC721SignedPayloadOutput payload;
156172
}
157173

158174
public class ERC721Signature

Assets/WebGLTemplates/Better2020/index.html

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,6 @@
9898
return value;
9999
};
100100

101-
const parserTransform = (key, value) => {
102-
// if we find a BigNumber then make it into a string (since that is safe)
103-
if (key.toLowerCase().includes("time")) {
104-
return new Date(value);
105-
}
106-
return value;
107-
};
108-
109101
const w = window;
110102
w.bridge = {};
111103
w.bridge.initialize = (chain) => {
@@ -137,10 +129,10 @@
137129
const routeArgs = route.split(".")
138130
const addr = routeArgs[0];
139131
const contract = await w.thirdweb.getContract(addr)
140-
const fnArgs = JSON.parse(payload, parserTransform).arguments;
132+
const fnArgs = JSON.parse(payload).arguments;
141133
const parsedArgs = fnArgs.map((arg) => {
142134
try {
143-
return JSON.parse(arg, parserTransform);
135+
return JSON.parse(arg);
144136
} catch (e) {
145137
return arg;
146138
}

0 commit comments

Comments
 (0)