Skip to content

Commit 6d14859

Browse files
committed
Working Gasless Support + fixes
1 parent d80e3f5 commit 6d14859

File tree

5 files changed

+42
-31
lines changed

5 files changed

+42
-31
lines changed

Assets/Thirdweb/Core/Contract Definitions/Forwarder/ContractDefinition/ForwardRequest.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Numerics;
55
using Nethereum.Hex.HexTypes;
66
using Nethereum.ABI.FunctionEncoding.Attributes;
7+
using Newtonsoft.Json;
78

89
namespace Thirdweb.Contracts.Forwarder.ContractDefinition
910
{
@@ -12,21 +13,27 @@ public partial class ForwardRequest : ForwardRequestBase { }
1213
public class ForwardRequestBase
1314
{
1415
[Parameter("address", "from", 1)]
16+
[JsonProperty("from")]
1517
public virtual string From { get; set; }
1618

1719
[Parameter("address", "to", 2)]
20+
[JsonProperty("to")]
1821
public virtual string To { get; set; }
1922

2023
[Parameter("uint256", "value", 3)]
24+
[JsonProperty("value")]
2125
public virtual BigInteger Value { get; set; }
2226

2327
[Parameter("uint256", "gas", 4)]
28+
[JsonProperty("gas")]
2429
public virtual BigInteger Gas { get; set; }
2530

2631
[Parameter("uint256", "nonce", 5)]
32+
[JsonProperty("nonce")]
2733
public virtual BigInteger Nonce { get; set; }
2834

2935
[Parameter("bytes", "data", 6)]
36+
[JsonProperty("data")]
3037
public virtual string Data { get; set; }
3138
}
3239
}

Assets/Thirdweb/Core/Scripts/TransactionManager.cs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,7 @@ public static async Task<TransactionReceipt> ThirdwebWriteRawResult<TWFunction>(
4949
functionMessage.Gas = gas.Value < 100000 ? 100000 : gas.Value;
5050
functionMessage.FromAddress = await ThirdwebManager.Instance.SDK.wallet.GetAddress();
5151

52-
if (
53-
ThirdwebManager.Instance.SDK.options.gasless != null
54-
&& ThirdwebManager.Instance.SDK.options.gasless.Value.openzeppelin != null
55-
&& !string.IsNullOrEmpty(ThirdwebManager.Instance.SDK.options.gasless.Value.openzeppelin.Value.relayerUrl)
56-
&& !string.IsNullOrEmpty(ThirdwebManager.Instance.SDK.options.gasless.Value.openzeppelin.Value.relayerForwarderAddress)
57-
)
52+
if (ThirdwebManager.Instance.SDK.options.gasless != null && ThirdwebManager.Instance.SDK.options.gasless.Value.openzeppelin != null)
5853
{
5954
string relayerUrl = ThirdwebManager.Instance.SDK.options.gasless.Value.openzeppelin?.relayerUrl;
6055
string relayerForwarderAddress = ThirdwebManager.Instance.SDK.options.gasless.Value.openzeppelin?.relayerForwarderAddress;
@@ -82,8 +77,6 @@ public static async Task<TransactionReceipt> ThirdwebWriteRawResult<TWFunction>(
8277

8378
string txHash = null;
8479

85-
Debug.Log(JsonConvert.SerializeObject(postData));
86-
8780
using (UnityWebRequest req = UnityWebRequest.Post(relayerUrl, ""))
8881
{
8982
byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(postData));
@@ -93,17 +86,18 @@ public static async Task<TransactionReceipt> ThirdwebWriteRawResult<TWFunction>(
9386
await req.SendWebRequest();
9487
if (req.result != UnityWebRequest.Result.Success)
9588
{
96-
req.Dispose();
9789
throw new UnityException(
9890
$"Forward Request Failed!\nError: {req.downloadHandler.text}\nRelayer URL: {relayerUrl}\nRelayer Forwarder Address: {relayerForwarderAddress}\nRequest: {request}\nSignature: {signature}\nPost Data: {postData}"
9991
);
10092
}
10193
else
10294
{
103-
txHash = req.downloadHandler.text;
95+
var response = JsonConvert.DeserializeObject<RelayerResponse>(req.downloadHandler.text);
96+
var result = JsonConvert.DeserializeObject<RelayerResult>(response.result);
97+
txHash = result.txHash;
98+
Debug.Log(txHash);
10499
}
105100
}
106-
107101
return await ThirdwebManager.Instance.SDK.nativeSession.web3.TransactionReceiptPolling.PollForReceiptAsync(txHash);
108102
}
109103
else
@@ -113,12 +107,33 @@ public static async Task<TransactionReceipt> ThirdwebWriteRawResult<TWFunction>(
113107
}
114108
}
115109

110+
[System.Serializable]
111+
public struct RelayerResponse
112+
{
113+
[JsonProperty("result")]
114+
public string result;
115+
}
116+
117+
[System.Serializable]
118+
public struct RelayerResult
119+
{
120+
[JsonProperty("txHash")]
121+
public string txHash;
122+
}
123+
116124
[System.Serializable]
117125
public struct RelayerRequest
118126
{
127+
[JsonProperty("request")]
119128
public MinimalForwarder.ForwardRequest request;
129+
130+
[JsonProperty("signature")]
120131
public string signature;
132+
133+
[JsonProperty("forwarderAddress")]
121134
public string forwarderAddress;
135+
136+
[JsonProperty("type")]
122137
public string type;
123138

124139
public RelayerRequest(ForwardRequest request, string signature, string forwarderAddress)

Assets/Thirdweb/Examples/Prefabs/ThirdwebManager.prefab

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ MonoBehaviour:
5252
draggable: 1
5353
expandable: 1
5454
multipleSelection: 1
55-
isExpanded: 1
55+
isExpanded: 0
5656
label:
5757
m_Text: Keys
5858
m_Image: {fileID: 0}
@@ -67,7 +67,7 @@ MonoBehaviour:
6767
elementNameOverride:
6868
elementIcon: {fileID: 0}
6969
reqReferences: {fileID: 0}
70-
isExpanded: 1
70+
isExpanded: 0
7171
_keyValues: 000000000100000002000000030000000400000005000000060000000700000008000000090000000a0000000b0000000c0000000d000000
7272
_keys: 000000000100000002000000030000000400000005000000060000000700000008000000090000000a0000000b0000000c0000000d000000
7373
_values:
@@ -114,5 +114,5 @@ MonoBehaviour:
114114
chainId: 97
115115
rpcOverride:
116116
storageIpfsGatewayUrl: https://gateway.ipfscdn.io/ipfs/
117-
relayerUrl:
118-
relayerForwarderAddress:
117+
relayerUrl: https://api.defender.openzeppelin.com/autotasks/7d795312-855d-4f02-900a-30c1dde211cb/runs/webhook/76da2beb-fbb1-4082-bbb8-d4429dedee81/E33wsMacq1ZDCQVHPTZVo
118+
relayerForwarderAddress: 0x5001A14CA6163143316a7C614e30e6041033Ac20

Assets/Thirdweb/Examples/Scenes/Scene_Prefabs.unity

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,22 +2280,6 @@ PrefabInstance:
22802280
m_Modification:
22812281
m_TransformParent: {fileID: 0}
22822282
m_Modifications:
2283-
- target: {fileID: 4404896360829706404, guid: 379ed01658d62a14484f953196ff19db, type: 3}
2284-
propertyPath: relayerUrl
2285-
value: https://api.defender.openzeppelin.com/autotasks/7d795312-855d-4f02-900a-30c1dde211cb/runs/webhook/76da2beb-fbb1-4082-bbb8-d4429dedee81/E33wsMacq1ZDCQVHPTZVo
2286-
objectReference: {fileID: 0}
2287-
- target: {fileID: 4404896360829706404, guid: 379ed01658d62a14484f953196ff19db, type: 3}
2288-
propertyPath: relayerForwarderAddress
2289-
value: 0x5001A14CA6163143316a7C614e30e6041033Ac20
2290-
objectReference: {fileID: 0}
2291-
- target: {fileID: 4404896360829706404, guid: 379ed01658d62a14484f953196ff19db, type: 3}
2292-
propertyPath: supportedChainData.isExpanded
2293-
value: 0
2294-
objectReference: {fileID: 0}
2295-
- target: {fileID: 4404896360829706404, guid: 379ed01658d62a14484f953196ff19db, type: 3}
2296-
propertyPath: supportedChainData.reorderableList.isExpanded
2297-
value: 0
2298-
objectReference: {fileID: 0}
22992283
- target: {fileID: 4404896360829706405, guid: 379ed01658d62a14484f953196ff19db, type: 3}
23002284
propertyPath: m_RootOrder
23012285
value: 3

Assets/Thirdweb/Examples/Scripts/Prefabs/Prefab_Writing.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public async void MintERC20()
4141
// }
4242

4343
// Claiming
44+
Debugger.Instance.Log("Request Sent", "Pending confirmation...");
4445
Contract contract = ThirdwebManager.Instance.SDK.GetContract(DROP_ERC20_CONTRACT);
4546
var result = await contract.ERC20.Claim("0.3");
4647
Debugger.Instance.Log("[Claim ERC20] Successful", result.ToString());
@@ -86,6 +87,7 @@ public async void MintERC721()
8687
// }
8788

8889
// NFT Drop Claiming
90+
Debugger.Instance.Log("Request Sent", "Pending confirmation...");
8991
Contract contract = ThirdwebManager.Instance.SDK.GetContract(DROP_ERC721_CONTRACT);
9092
var result = await contract.ERC721.Claim(1);
9193
Debugger.Instance.Log("[Claim ERC721] Successful", result[0].ToString());
@@ -143,6 +145,8 @@ public async void MintERC1155()
143145
// return;
144146
// }
145147

148+
// Edition Drop Claiming
149+
Debugger.Instance.Log("Request Sent", "Pending confirmation...");
146150
Contract contract = ThirdwebManager.Instance.SDK.GetContract(DROP_ERC1155_CONTRACT);
147151
TransactionResult transactionResult = await contract.ERC1155.Claim("0", 1);
148152
Debugger.Instance.Log("[Claim ERC1155] Successful", transactionResult.ToString());
@@ -220,6 +224,7 @@ public async void OpenPack()
220224
// var result = await pack.Create(newPackInput);
221225
// Debugger.Instance.Log("[Create Pack] Successful", result.ToString());
222226

227+
Debugger.Instance.Log("Request Sent", "Pending confirmation...");
223228
PackRewards rewards = await pack.Open("1");
224229
Debugger.Instance.Log("[Open Pack] Successful", rewards.ToString());
225230
}

0 commit comments

Comments
 (0)