Sfoglia il codice sorgente

fix: mint get gas and request log

wren 1 anno fa
parent
commit
0749ab9fd1
2 ha cambiato i file con 14 aggiunte e 2 eliminazioni
  1. 11 0
      js-runtime/src/app.js
  2. 3 2
      js-runtime/src/script/zksync2/tiktokfi/mint.js

+ 11 - 0
js-runtime/src/app.js

@@ -8,13 +8,24 @@ import syncSwapUsdcForEth from "./script/zksync2/sync/swapUsdcForEth.js"
 import tiktokfiMint from "./script/zksync2/tiktokfi/mint.js";
 
 const app = express();
+
 app.use(bodyParser.json());
+
+const endMiddleware = (req, res, next) => {
+    console.log(`request url: ${req.url}`);
+    console.log(`request params: ${JSON.stringify(req.body.params)}`);
+    console.log(`request address: ${JSON.stringify(req.body.wallet.address)}`);
+    next();
+};
+
+app.use(endMiddleware)
 app.use("/zk-mute-swap-eth-usdc", muteSwapEthForUsdc)
 app.use("/zk-mute-swap-usdc-eth", muteSwapUsdcForEth)
 app.use("/zk-sync-swap-eth-usdc", syncSwapEthForUsdc)
 app.use("/zk-sync-swap-usdc-eth", syncSwapUsdcForEth)
 app.use("/zk-sync-tiktokfi-mint", tiktokfiMint)
 
+
 app.use((err, req, res, next) => {
     // 处理错误逻辑
     console.error(err); // 输出错误信息到控制台

+ 3 - 2
js-runtime/src/script/zksync2/tiktokfi/mint.js

@@ -41,14 +41,15 @@ router.post("/", async (req, res) => {
         value: utils.parseEther("0.001"),
         data: input,
     }
-    const provider = new ethers.providers.JsonRpcProvider('https://testnet.era.zksync.dev');
+    const provider = new ethers.providers.JsonRpcProvider('https://mainnet.era.zksync.io');
     const wallet = new Wallet(signer.privateKey, provider);
     tx.gasLimit = await wallet.estimateGas(tx);
     const trnsaction = await wallet.sendTransaction(tx);
     await trnsaction.wait();
     // get tx receipt
     const receipt = await provider.getTransactionReceipt(trnsaction.hash);
-    const gas = utils.formatEther(receipt.gasUsed * trnsaction.gasPrice);
+    const tran = await provider.getTransaction(trnsaction.hash);
+    const gas = utils.formatEther(receipt.gasUsed * tran.gasPrice);
     //获取地址余额并将其转换为可读的数字
     const balance = await wallet.getBalance()
     const balanceStr = utils.formatEther(balance);