Skip to content

Commit 954fddf

Browse files
committed
Support gas estimation from Smart Wallet client, decouple tx receipt in contract.Write
1 parent 5b09722 commit 954fddf

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

Assets/Thirdweb/Core/Scripts/AccountAbstraction/Core/SmartWallet.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ internal async Task<RpcResponseMessage> Request(RpcRequestMessage requestMessage
152152
var chainId = await PersonalWeb3.Eth.ChainId.SendRequestAsync();
153153
return new RpcResponseMessage(requestMessage.Id, chainId.HexValue);
154154
}
155+
else if (requestMessage.Method == "eth_estimateGas")
156+
{
157+
var web3 = Utils.GetWeb3();
158+
var parameters = JsonConvert.DeserializeObject<object[]>(JsonConvert.SerializeObject(requestMessage.RawParameters));
159+
var txInput = JsonConvert.DeserializeObject<TransactionInput>(JsonConvert.SerializeObject(parameters[0]));
160+
var result = await web3.Eth.Transactions.EstimateGas.SendRequestAsync(txInput);
161+
return new RpcResponseMessage(requestMessage.Id, result.HexValue);
162+
}
155163
else
156164
{
157165
throw new NotImplementedException("Method not supported: " + requestMessage.Method);

Assets/Thirdweb/Core/Scripts/Contract.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public async Task<TransactionResult> Write(string functionName, TransactionReque
196196
if (this.abi == null)
197197
throw new UnityException("You must pass an ABI for native platform custom calls");
198198

199-
var contract = Utils.GetWeb3().Eth.GetContract(this.abi, this.address);
199+
var contract = ThirdwebManager.Instance.SDK.session.Web3.Eth.GetContract(this.abi, this.address);
200200

201201
var function = contract.GetFunction(functionName);
202202

@@ -209,15 +209,14 @@ public async Task<TransactionResult> Write(string functionName, TransactionReque
209209

210210
var gasPrice = transactionOverrides?.gasPrice != null ? new HexBigInteger(BigInteger.Parse(transactionOverrides?.gasPrice)) : null;
211211

212-
var receipt = await function.SendTransactionAndWaitForReceiptAsync(
212+
var hash = await function.SendTransactionAsync(
213213
from: transactionOverrides?.from ?? await ThirdwebManager.Instance.SDK.wallet.GetAddress(),
214214
gas: gas,
215215
gasPrice: gasPrice,
216216
value: value,
217-
receiptRequestCancellationToken: null,
218217
args
219218
);
220-
return receipt.ToTransactionResult();
219+
return await Transaction.WaitForTransactionResult(hash);
221220
}
222221
}
223222

0 commit comments

Comments
 (0)