@@ -41,13 +41,9 @@ public struct GasCosts
41
41
/// </summary>
42
42
public class Transaction
43
43
{
44
- private readonly Contract contract ;
45
- private readonly string fnName ;
46
- private object [ ] fnArgs ;
47
-
48
- /// <summary>
49
- /// Gets the transaction input.
50
- /// </summary>
44
+ public Contract Contract { get ; private set ; }
45
+ public string FunctionName { get ; private set ; }
46
+ public object [ ] FunctionArgs { get ; private set ; }
51
47
public TransactionInput Input { get ; private set ; }
52
48
53
49
/// <summary>
@@ -57,10 +53,15 @@ public class Transaction
57
53
/// <param name="txInput">The transaction input.</param>
58
54
public Transaction ( Contract contract , TransactionInput txInput , string fnName , object [ ] fnArgs )
59
55
{
60
- this . contract = contract ;
56
+ this . Contract = contract ;
57
+ this . Input = txInput ;
58
+ this . FunctionName = fnName ;
59
+ this . FunctionArgs = fnArgs ;
60
+ }
61
+
62
+ public Transaction ( TransactionInput txInput )
63
+ {
61
64
this . Input = txInput ;
62
- this . fnName = fnName ;
63
- this . fnArgs = fnArgs ;
64
65
}
65
66
66
67
/// <summary>
@@ -202,12 +203,12 @@ public Transaction SetArgs(params object[] args)
202
203
{
203
204
if ( Utils . IsWebGLBuild ( ) )
204
205
{
205
- this . fnArgs = args ;
206
+ this . FunctionArgs = args ;
206
207
}
207
208
else
208
209
{
209
210
var web3 = Utils . GetWeb3 ( ) ;
210
- var function = web3 . Eth . GetContract ( contract . ABI , contract . Address ) . GetFunction ( Input . To ) ;
211
+ var function = web3 . Eth . GetContract ( Contract . ABI , Contract . Address ) . GetFunction ( Input . To ) ;
211
212
Input . Data = function . GetData ( args ) ;
212
213
}
213
214
return this ;
@@ -221,17 +222,12 @@ public async Task<BigInteger> GetGasPrice()
221
222
{
222
223
if ( Utils . IsWebGLBuild ( ) )
223
224
{
224
- var val = await Bridge . InvokeRoute < string > ( GetTxBuilderRoute ( "getGasPrice" ) , Utils . ToJsonStringArray ( Input , fnName , fnArgs ) ) ;
225
+ var val = await Bridge . InvokeRoute < string > ( GetTxBuilderRoute ( "getGasPrice" ) , Utils . ToJsonStringArray ( Input , FunctionName , FunctionArgs ) ) ;
225
226
return BigInteger . Parse ( val ) ;
226
227
}
227
228
else
228
229
{
229
- var web3 = Utils . GetWeb3 ( ) ;
230
- var gasPrice = await web3 . Eth . GasPrice . SendRequestAsync ( ) ;
231
- var maxGasPrice = BigInteger . Parse ( "300000000000" ) ; // 300 Gwei in Wei
232
- var extraTip = gasPrice . Value / 10 ; // +10%
233
- var txGasPrice = gasPrice . Value + extraTip ;
234
- return txGasPrice > maxGasPrice ? maxGasPrice : txGasPrice ;
230
+ return await Utils . GetLegacyGasPriceAsync ( ThirdwebManager . Instance . SDK . Session . ChainId ) ;
235
231
}
236
232
}
237
233
@@ -243,7 +239,7 @@ public async Task<BigInteger> EstimateGasLimit()
243
239
{
244
240
if ( Utils . IsWebGLBuild ( ) )
245
241
{
246
- var val = await Bridge . InvokeRoute < string > ( GetTxBuilderRoute ( "estimateGasLimit" ) , Utils . ToJsonStringArray ( Input , fnName , fnArgs ) ) ;
242
+ var val = await Bridge . InvokeRoute < string > ( GetTxBuilderRoute ( "estimateGasLimit" ) , Utils . ToJsonStringArray ( Input , FunctionName , FunctionArgs ) ) ;
247
243
return BigInteger . Parse ( val ) ;
248
244
}
249
245
else
@@ -262,7 +258,7 @@ public async Task<GasCosts> EstimateGasCosts()
262
258
{
263
259
if ( Utils . IsWebGLBuild ( ) )
264
260
{
265
- return await Bridge . InvokeRoute < GasCosts > ( GetTxBuilderRoute ( "estimateGasCosts" ) , Utils . ToJsonStringArray ( Input , fnName , fnArgs ) ) ;
261
+ return await Bridge . InvokeRoute < GasCosts > ( GetTxBuilderRoute ( "estimateGasCosts" ) , Utils . ToJsonStringArray ( Input , FunctionName , FunctionArgs ) ) ;
266
262
}
267
263
else
268
264
{
@@ -294,7 +290,7 @@ public async Task<string> Simulate()
294
290
{
295
291
if ( Utils . IsWebGLBuild ( ) )
296
292
{
297
- return JsonConvert . SerializeObject ( await Bridge . InvokeRoute < object > ( GetTxBuilderRoute ( "simulate" ) , Utils . ToJsonStringArray ( Input , fnName , fnArgs ) ) ) ;
293
+ return JsonConvert . SerializeObject ( await Bridge . InvokeRoute < object > ( GetTxBuilderRoute ( "simulate" ) , Utils . ToJsonStringArray ( Input , FunctionName , FunctionArgs ) ) ) ;
298
294
}
299
295
else
300
296
{
@@ -314,7 +310,7 @@ public async Task<string> Sign()
314
310
315
311
if ( Utils . IsWebGLBuild ( ) )
316
312
{
317
- return await Bridge . InvokeRoute < string > ( GetTxBuilderRoute ( "sign" ) , Utils . ToJsonStringArray ( Input , fnName , fnArgs ) ) ;
313
+ return await Bridge . InvokeRoute < string > ( GetTxBuilderRoute ( "sign" ) , Utils . ToJsonStringArray ( Input , FunctionName , FunctionArgs ) ) ;
318
314
}
319
315
else
320
316
{
@@ -371,7 +367,7 @@ public async Task<TransactionResult> SendAndWaitForTransactionResult(bool? gasle
371
367
else
372
368
action = "executeGasless" ;
373
369
374
- return await Bridge . InvokeRoute < TransactionResult > ( GetTxBuilderRoute ( action ) , Utils . ToJsonStringArray ( Input , fnName , fnArgs ) ) ;
370
+ return await Bridge . InvokeRoute < TransactionResult > ( GetTxBuilderRoute ( action ) , Utils . ToJsonStringArray ( Input , FunctionName , FunctionArgs ) ) ;
375
371
}
376
372
else
377
373
{
@@ -437,30 +433,54 @@ private async Task<string> Send()
437
433
{
438
434
if ( Utils . IsWebGLBuild ( ) )
439
435
{
440
- return await Bridge . InvokeRoute < string > ( GetTxBuilderRoute ( "send" ) , Utils . ToJsonStringArray ( Input , fnName , fnArgs ) ) ;
436
+ return await Bridge . InvokeRoute < string > ( GetTxBuilderRoute ( "send" ) , Utils . ToJsonStringArray ( Input , FunctionName , FunctionArgs ) ) ;
441
437
}
442
438
else
443
439
{
440
+ var supports1559 = Utils . Supports1559 ( ThirdwebManager . Instance . SDK . Session . ChainId . ToString ( ) ) ;
441
+ if ( supports1559 )
442
+ {
443
+ if ( Input . GasPrice == null )
444
+ {
445
+ var fees = await Utils . GetGasPriceAsync ( ThirdwebManager . Instance . SDK . Session . ChainId ) ;
446
+ if ( Input . MaxFeePerGas == null )
447
+ Input . MaxFeePerGas = new HexBigInteger ( fees . MaxFeePerGas ) ;
448
+ if ( Input . MaxPriorityFeePerGas == null )
449
+ Input . MaxPriorityFeePerGas = new HexBigInteger ( fees . MaxPriorityFeePerGas ) ;
450
+ }
451
+ }
452
+ else
453
+ {
454
+ if ( Input . MaxFeePerGas == null && Input . MaxPriorityFeePerGas == null )
455
+ {
456
+ ThirdwebDebug . Log ( "Using Legacy Gas Pricing" ) ;
457
+ Input . GasPrice = new HexBigInteger ( await Utils . GetLegacyGasPriceAsync ( ThirdwebManager . Instance . SDK . Session . ChainId ) ) ;
458
+ }
459
+ }
460
+
461
+ string hash ;
444
462
if (
445
463
ThirdwebManager . Instance . SDK . Session . ActiveWallet . GetSignerProvider ( ) == WalletProvider . LocalWallet
446
464
&& ThirdwebManager . Instance . SDK . Session . ActiveWallet . GetProvider ( ) != WalletProvider . SmartWallet
447
465
)
448
466
{
449
- return await ThirdwebManager . Instance . SDK . Session . Web3 . Eth . TransactionManager . SendTransactionAsync ( Input ) ;
467
+ hash = await ThirdwebManager . Instance . SDK . Session . Web3 . Eth . TransactionManager . SendTransactionAsync ( Input ) ;
450
468
}
451
469
else
452
470
{
453
471
var ethSendTx = new EthSendTransaction ( ThirdwebManager . Instance . SDK . Session . Web3 . Client ) ;
454
- return await ethSendTx . SendRequestAsync ( Input ) ;
472
+ hash = await ethSendTx . SendRequestAsync ( Input ) ;
455
473
}
474
+ ThirdwebDebug . Log ( $ "Transaction hash: { hash } ") ;
475
+ return hash ;
456
476
}
457
477
}
458
478
459
479
private async Task < string > SendGasless ( )
460
480
{
461
481
if ( Utils . IsWebGLBuild ( ) )
462
482
{
463
- return await Bridge . InvokeRoute < string > ( GetTxBuilderRoute ( "sendGasless" ) , Utils . ToJsonStringArray ( Input , fnName , fnArgs ) ) ;
483
+ return await Bridge . InvokeRoute < string > ( GetTxBuilderRoute ( "sendGasless" ) , Utils . ToJsonStringArray ( Input , FunctionName , FunctionArgs ) ) ;
464
484
}
465
485
else
466
486
{
@@ -525,8 +545,49 @@ private async Task<string> SendGasless()
525
545
526
546
private string GetTxBuilderRoute ( string action )
527
547
{
528
- string route = contract . ABI != null ? $ "{ contract . Address } { Routable . subSeparator } { contract . ABI } " : contract . Address ;
548
+ string route = Contract . ABI != null ? $ "{ Contract . Address } { Routable . subSeparator } { Contract . ABI } " : Contract . Address ;
529
549
return $ "{ route } { Routable . separator } tx{ Routable . separator } { action } ";
530
550
}
531
551
}
552
+
553
+ [ System . Serializable ]
554
+ public struct RelayerResponse
555
+ {
556
+ [ JsonProperty ( "status" ) ]
557
+ public string status ;
558
+
559
+ [ JsonProperty ( "result" ) ]
560
+ public string result ;
561
+ }
562
+
563
+ [ System . Serializable ]
564
+ public struct RelayerResult
565
+ {
566
+ [ JsonProperty ( "txHash" ) ]
567
+ public string txHash ;
568
+ }
569
+
570
+ [ System . Serializable ]
571
+ public struct RelayerRequest
572
+ {
573
+ [ JsonProperty ( "request" ) ]
574
+ public MinimalForwarder . ForwardRequest request ;
575
+
576
+ [ JsonProperty ( "signature" ) ]
577
+ public string signature ;
578
+
579
+ [ JsonProperty ( "forwarderAddress" ) ]
580
+ public string forwarderAddress ;
581
+
582
+ [ JsonProperty ( "type" ) ]
583
+ public string type ;
584
+
585
+ public RelayerRequest ( MinimalForwarder . ForwardRequest request , string signature , string forwarderAddress )
586
+ {
587
+ this . request = request ;
588
+ this . signature = signature ;
589
+ this . forwarderAddress = forwarderAddress ;
590
+ this . type = "forward" ;
591
+ }
592
+ }
532
593
}
0 commit comments