@@ -41,13 +41,9 @@ public struct GasCosts
4141 /// </summary>
4242 public class Transaction
4343 {
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 ; }
5147 public TransactionInput Input { get ; private set ; }
5248
5349 /// <summary>
@@ -57,10 +53,15 @@ public class Transaction
5753 /// <param name="txInput">The transaction input.</param>
5854 public Transaction ( Contract contract , TransactionInput txInput , string fnName , object [ ] fnArgs )
5955 {
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+ {
6164 this . Input = txInput ;
62- this . fnName = fnName ;
63- this . fnArgs = fnArgs ;
6465 }
6566
6667 /// <summary>
@@ -202,12 +203,12 @@ public Transaction SetArgs(params object[] args)
202203 {
203204 if ( Utils . IsWebGLBuild ( ) )
204205 {
205- this . fnArgs = args ;
206+ this . FunctionArgs = args ;
206207 }
207208 else
208209 {
209210 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 ) ;
211212 Input . Data = function . GetData ( args ) ;
212213 }
213214 return this ;
@@ -221,17 +222,12 @@ public async Task<BigInteger> GetGasPrice()
221222 {
222223 if ( Utils . IsWebGLBuild ( ) )
223224 {
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 ) ) ;
225226 return BigInteger . Parse ( val ) ;
226227 }
227228 else
228229 {
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 ) ;
235231 }
236232 }
237233
@@ -243,7 +239,7 @@ public async Task<BigInteger> EstimateGasLimit()
243239 {
244240 if ( Utils . IsWebGLBuild ( ) )
245241 {
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 ) ) ;
247243 return BigInteger . Parse ( val ) ;
248244 }
249245 else
@@ -262,7 +258,7 @@ public async Task<GasCosts> EstimateGasCosts()
262258 {
263259 if ( Utils . IsWebGLBuild ( ) )
264260 {
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 ) ) ;
266262 }
267263 else
268264 {
@@ -294,7 +290,7 @@ public async Task<string> Simulate()
294290 {
295291 if ( Utils . IsWebGLBuild ( ) )
296292 {
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 ) ) ) ;
298294 }
299295 else
300296 {
@@ -314,7 +310,7 @@ public async Task<string> Sign()
314310
315311 if ( Utils . IsWebGLBuild ( ) )
316312 {
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 ) ) ;
318314 }
319315 else
320316 {
@@ -371,7 +367,7 @@ public async Task<TransactionResult> SendAndWaitForTransactionResult(bool? gasle
371367 else
372368 action = "executeGasless" ;
373369
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 ) ) ;
375371 }
376372 else
377373 {
@@ -437,30 +433,54 @@ private async Task<string> Send()
437433 {
438434 if ( Utils . IsWebGLBuild ( ) )
439435 {
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 ) ) ;
441437 }
442438 else
443439 {
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 ;
444462 if (
445463 ThirdwebManager . Instance . SDK . Session . ActiveWallet . GetSignerProvider ( ) == WalletProvider . LocalWallet
446464 && ThirdwebManager . Instance . SDK . Session . ActiveWallet . GetProvider ( ) != WalletProvider . SmartWallet
447465 )
448466 {
449- return await ThirdwebManager . Instance . SDK . Session . Web3 . Eth . TransactionManager . SendTransactionAsync ( Input ) ;
467+ hash = await ThirdwebManager . Instance . SDK . Session . Web3 . Eth . TransactionManager . SendTransactionAsync ( Input ) ;
450468 }
451469 else
452470 {
453471 var ethSendTx = new EthSendTransaction ( ThirdwebManager . Instance . SDK . Session . Web3 . Client ) ;
454- return await ethSendTx . SendRequestAsync ( Input ) ;
472+ hash = await ethSendTx . SendRequestAsync ( Input ) ;
455473 }
474+ ThirdwebDebug . Log ( $ "Transaction hash: { hash } ") ;
475+ return hash ;
456476 }
457477 }
458478
459479 private async Task < string > SendGasless ( )
460480 {
461481 if ( Utils . IsWebGLBuild ( ) )
462482 {
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 ) ) ;
464484 }
465485 else
466486 {
@@ -525,8 +545,49 @@ private async Task<string> SendGasless()
525545
526546 private string GetTxBuilderRoute ( string action )
527547 {
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 ;
529549 return $ "{ route } { Routable . separator } tx{ Routable . separator } { action } ";
530550 }
531551 }
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+ }
532593}
0 commit comments