Skip to content

Commit 000a601

Browse files
committed
Gasless req partial fix
1 parent 1a11c52 commit 000a601

File tree

3 files changed

+61
-39
lines changed

3 files changed

+61
-39
lines changed

Assets/Thirdweb/Core/Scripts/TransactionManager.cs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public static async Task<TransactionReceipt> ThirdwebWriteRawResult<TWFunction>(
6060
string relayerUrl = ThirdwebManager.Instance.SDK.options.gasless.Value.openzeppelin?.relayerUrl;
6161
string relayerForwarderAddress = ThirdwebManager.Instance.SDK.options.gasless.Value.openzeppelin?.relayerForwarderAddress;
6262

63+
ContractBuilder b = new ContractBuilder(functionMessage.GetType(), contractAddress);
64+
var f = b.GetFunctionBuilder<TWFunction>();
65+
6366
var request = new MinimalForwarder.ForwardRequest()
6467
{
6568
From = functionMessage.FromAddress,
@@ -68,32 +71,34 @@ public static async Task<TransactionReceipt> ThirdwebWriteRawResult<TWFunction>(
6871
Gas = functionMessage.Gas.Value,
6972
Nonce = (
7073
await ThirdwebRead<MinimalForwarder.GetNonceFunction, MinimalForwarder.GetNonceOutputDTO>(
71-
"0x5001A14CA6163143316a7C614e30e6041033Ac20",
74+
relayerForwarderAddress,
7275
new MinimalForwarder.GetNonceFunction() { From = functionMessage.FromAddress }
7376
)
7477
).ReturnValue1,
75-
Data = functionMessage.GetCallData()
78+
Data = f.GetDataAsBytes(functionMessage)
7679
};
7780

7881
var signature = await EIP712.GenerateSignature_MinimalForwarder("GSNv2 Forwarder", "0.0.1", ThirdwebManager.Instance.SDK.nativeSession.lastChainId, relayerForwarderAddress, request);
7982

8083
var postData = new RelayerRequest(request, signature, relayerForwarderAddress);
8184

8285
string txHash = null;
83-
using (UnityWebRequest req = UnityWebRequest.Post(relayerUrl, JsonConvert.SerializeObject(postData)))
84-
{
85-
await req.SendWebRequest();
8686

87-
if (req.result != UnityWebRequest.Result.Success)
88-
{
89-
throw new UnityException(
90-
$"Forward Request Failed!\nError: {req.downloadHandler.text}\nRelayer URL: {relayerUrl}\nRelayer Forwarder Address: {relayerForwarderAddress}\nRequest: {request}\nSignature: {signature}\nPost Data: {postData}"
91-
);
92-
}
93-
else
94-
{
95-
txHash = req.downloadHandler.text;
96-
}
87+
var req = new UnityWebRequest(relayerUrl, "POST");
88+
byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(postData));
89+
req.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
90+
req.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
91+
req.SetRequestHeader("Content-Type", "application/json");
92+
await req.SendWebRequest();
93+
if (req.result != UnityWebRequest.Result.Success)
94+
{
95+
throw new UnityException(
96+
$"Forward Request Failed!\nError: {req.downloadHandler.text}\nRelayer URL: {relayerUrl}\nRelayer Forwarder Address: {relayerForwarderAddress}\nRequest: {request}\nSignature: {signature}\nPost Data: {postData}"
97+
);
98+
}
99+
else
100+
{
101+
txHash = req.downloadHandler.text;
97102
}
98103

99104
return await ThirdwebManager.Instance.SDK.nativeSession.web3.TransactionReceiptPolling.PollForReceiptAsync(txHash);
@@ -104,6 +109,7 @@ public static async Task<TransactionReceipt> ThirdwebWriteRawResult<TWFunction>(
104109
}
105110
}
106111

112+
[System.Serializable]
107113
public struct RelayerRequest
108114
{
109115
public MinimalForwarder.ForwardRequest request;

Assets/Thirdweb/Examples/Scenes/Scene_Prefabs.unity

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,6 +2236,22 @@ PrefabInstance:
22362236
m_Modification:
22372237
m_TransformParent: {fileID: 0}
22382238
m_Modifications:
2239+
- target: {fileID: 4404896360829706404, guid: 379ed01658d62a14484f953196ff19db, type: 3}
2240+
propertyPath: relayerUrl
2241+
value: https://api.defender.openzeppelin.com/autotasks/b511c05f-2e3f-4cf0-b7dc-b0e41dee3db1/runs/webhook/76da2beb-fbb1-4082-bbb8-d4429dedee81/61fqU3Avg7fheoP4qjehVt
2242+
objectReference: {fileID: 0}
2243+
- target: {fileID: 4404896360829706404, guid: 379ed01658d62a14484f953196ff19db, type: 3}
2244+
propertyPath: relayerForwarderAddress
2245+
value: 0x5001A14CA6163143316a7C614e30e6041033Ac20
2246+
objectReference: {fileID: 0}
2247+
- target: {fileID: 4404896360829706404, guid: 379ed01658d62a14484f953196ff19db, type: 3}
2248+
propertyPath: supportedChainData.isExpanded
2249+
value: 0
2250+
objectReference: {fileID: 0}
2251+
- target: {fileID: 4404896360829706404, guid: 379ed01658d62a14484f953196ff19db, type: 3}
2252+
propertyPath: supportedChainData.reorderableList.isExpanded
2253+
value: 0
2254+
objectReference: {fileID: 0}
22392255
- target: {fileID: 4404896360829706405, guid: 379ed01658d62a14484f953196ff19db, type: 3}
22402256
propertyPath: m_RootOrder
22412257
value: 3

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,39 +56,39 @@ public async void MintERC721()
5656
try
5757
{
5858
// NFT Collection Signature Minting (Requires Mint Permission)
59-
Contract contract = ThirdwebManager.Instance.SDK.GetContract(TOKEN_ERC721_CONTRACT);
59+
// Contract contract = ThirdwebManager.Instance.SDK.GetContract(TOKEN_ERC721_CONTRACT);
6060

61-
NFTMetadata meta = new NFTMetadata()
62-
{
63-
name = "Unity NFT",
64-
description = "Minted From Unity",
65-
image = "ipfs://QmbpciV7R5SSPb6aT9kEBAxoYoXBUsStJkMpxzymV4ZcVc",
66-
};
61+
// NFTMetadata meta = new NFTMetadata()
62+
// {
63+
// name = "Unity NFT",
64+
// description = "Minted From Unity",
65+
// image = "ipfs://QmbpciV7R5SSPb6aT9kEBAxoYoXBUsStJkMpxzymV4ZcVc",
66+
// };
6767

6868
// Minting
6969
// var result = await contract.ERC721.Mint(meta);
7070
// Debugger.Instance.Log("[Mint ERC721] Successful", result.ToString());
7171

7272
// Signature Minting
73-
var receiverAddress = await ThirdwebManager.Instance.SDK.wallet.GetAddress();
74-
var payload = new ERC721MintPayload(receiverAddress, meta);
75-
var signedPayload = await contract.ERC721.signature.Generate(payload);
76-
bool isValid = await contract.ERC721.signature.Verify(signedPayload);
77-
if (isValid)
78-
{
79-
Debugger.Instance.Log("Sign minting ERC721...", $"Signature: {signedPayload.signature}");
80-
var result = await contract.ERC721.signature.Mint(signedPayload);
81-
Debugger.Instance.Log("[Mint (Signature) ERC721] Successful", result.ToString());
82-
}
83-
else
84-
{
85-
Debugger.Instance.Log("Signature Invalid", $"Signature: {signedPayload.signature} is invalid!");
86-
}
73+
// var receiverAddress = await ThirdwebManager.Instance.SDK.wallet.GetAddress();
74+
// var payload = new ERC721MintPayload(receiverAddress, meta);
75+
// var signedPayload = await contract.ERC721.signature.Generate(payload);
76+
// bool isValid = await contract.ERC721.signature.Verify(signedPayload);
77+
// if (isValid)
78+
// {
79+
// Debugger.Instance.Log("Sign minting ERC721...", $"Signature: {signedPayload.signature}");
80+
// var result = await contract.ERC721.signature.Mint(signedPayload);
81+
// Debugger.Instance.Log("[Mint (Signature) ERC721] Successful", result.ToString());
82+
// }
83+
// else
84+
// {
85+
// Debugger.Instance.Log("Signature Invalid", $"Signature: {signedPayload.signature} is invalid!");
86+
// }
8787

8888
// NFT Drop Claiming
89-
// Contract contract = ThirdwebManager.Instance.SDK.GetContract(DROP_ERC721_CONTRACT);
90-
// var result = await contract.ERC721.Claim(1);
91-
// Debugger.Instance.Log("[Claim ERC721] Successful", result[0].ToString());
89+
Contract contract = ThirdwebManager.Instance.SDK.GetContract(DROP_ERC721_CONTRACT);
90+
var result = await contract.ERC721.Claim(1);
91+
Debugger.Instance.Log("[Claim ERC721] Successful", result[0].ToString());
9292
}
9393
catch (System.Exception e)
9494
{

0 commit comments

Comments
 (0)