From 30e1fb6b6a22ddadd22998a5934382bc06cb973e Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Sun, 28 Apr 2024 16:17:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8A=E9=93=BE=E6=B5=81?= =?UTF-8?q?=E7=A8=8B,=20=E5=B0=86=E8=AE=A1=E7=AE=97gas=E6=B6=88=E8=80=97?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E6=9C=AC=E5=9C=B0=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/wallet/index.js | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/wallet/index.js b/src/wallet/index.js index 8e13d2f..3d3e142 100644 --- a/src/wallet/index.js +++ b/src/wallet/index.js @@ -331,6 +331,22 @@ export class Wallet { return new web3.eth.Contract(abi, address, { from: user }); } + async estimateGas(address, data) { + const params = [ + { + data, + from: address, + to: process.env.VUE_APP_CONTRACT, + }, + 'latest', + ] + let res = await requestChain(chainData.rpc, 'eth_estimateGas', params) + if (res.error) { + throw new Error(res.error.message) + } + return res.result + } + async chainCheckIn(address) { let checkResult = await this.fetchCheckInStatus(address) if (checkResult) { @@ -341,7 +357,8 @@ export class Wallet { let gasPrice = await web3.eth.getGasPrice() // console.log('chainCheckIn gasPrice: ', gasPrice) gasPrice = gasPrice * 2n - let gasLimit = await instance.methods.dailyCheckin().estimateGas(); + let gasLimit = await this.estimateGas(address, '0xd8edeb1b'); + console.log('gasLimit: ', gasLimit, 'gasPrice:', gasPrice) return instance.methods.dailyCheckin().send({ from: address, gasPrice, gasLimit }); } @@ -369,7 +386,10 @@ export class Wallet { const instance = this.initInstance(web3, process.env.VUE_APP_CONTRACT, treasureAbi, address); let gasPrice = await web3.eth.getGasPrice() gasPrice = gasPrice * 2n - let gasLimit = await instance.methods.explore(idBN).estimateGas({ from: address }); + // let gasLimit = await instance.methods.explore(idBN).estimateGas({ from: address }); + const dataStr = '0x6457e389' + exploreId.padStart(64, '0'); + const gasLimit = await this.estimateGas(address, dataStr) + console.log('gasLimit: ', gasLimit, 'gasPrice:', gasPrice) return instance.methods.explore(idBN).send({ from: address, gasPrice, gasLimit }); } @@ -399,7 +419,10 @@ export class Wallet { const instance = this.initInstance(web3, process.env.VUE_APP_CONTRACT, treasureAbi, address); let gasPrice = await web3.eth.getGasPrice() gasPrice = gasPrice * 2n - let gasLimit = await instance.methods.enhanceBox(codeBn).estimateGas({ from: address }); + // let gasLimit = await instance.methods.enhanceBox(codeBn).estimateGas({ from: address }); + const dataStr = '0x44a17e06' + codeHex.padStart(64, '0'); + const gasLimit = await this.estimateGas(address, dataStr) + console.log('gasLimit: ', gasLimit, 'gasPrice:', gasPrice) return instance.methods.enhanceBox(codeBn).send({ from: address, gasPrice, gasLimit }); } @@ -431,7 +454,10 @@ export class Wallet { let gasPrice = await web3.eth.getGasPrice() gasPrice = gasPrice * 2n - let gasLimit = await instance.methods.openBox(boxIdBN).estimateGas({ from: address }); + // let gasLimit = await instance.methods.openBox(boxIdBN).estimateGas({ from: address }); + const dataStr = '0xb1e5e2b7' + boxId.padStart(64, '0'); + const gasLimit = await this.estimateGas(address, dataStr) + console.log('gasLimit: ', gasLimit, 'gasPrice:', gasPrice) return instance.methods.openBox(boxIdBN).send({ from: address, gasPrice, gasLimit }); } @@ -461,7 +487,10 @@ export class Wallet { const instance = this.initInstance(web3, process.env.VUE_APP_CONTRACT, treasureAbi, address); let gasPrice = await web3.eth.getGasPrice() gasPrice = gasPrice * 2n - let gasLimit = await instance.methods.claimTaskReward(taskIdBN).estimateGas({ from: address }); + // let gasLimit = await instance.methods.claimTaskReward(taskIdBN).estimateGas({ from: address }); + const dataStr = '0x4052a9c7' + taskIdHex.padStart(64, '0'); + const gasLimit = await this.estimateGas(address, dataStr) + console.log('gasLimit: ', gasLimit, 'gasPrice:', gasPrice) return instance.methods.claimTaskReward(taskIdBN).send({ from: address, gasPrice, gasLimit }); }