Explorar o código

feat: mint nft

Wren hai 1 ano
pai
achega
e9547e583c

+ 4 - 2
js-runtime/src/app.js

@@ -5,13 +5,15 @@ import muteSwapEthForUsdc from "./script/zksync2/mute/swap.js";
 import muteSwapUsdcForEth from "./script/zksync2/mute/swapUsdcForEth.js"
 import syncSwapEthForUsdc from "./script/zksync2/sync/swapEthForUsdc.js";
 import syncSwapUsdcForEth from "./script/zksync2/sync/swapUsdcForEth.js"
+import tiktokfiMint from "./script/zksync2/tiktokfi/mint.js";
 
 const app = express();
 app.use(bodyParser.json());
 app.use("/zk-mute-swap-eth-usdc", muteSwapEthForUsdc)
-app.use("/zk-mute-swap-usdc-eth",muteSwapUsdcForEth)
+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-swap-usdc-eth", syncSwapUsdcForEth)
+app.use("/zk-sync-tiktokfi-mint", tiktokfiMint)
 
 app.use((err, req, res, next) => {
     // 处理错误逻辑

+ 58 - 0
js-runtime/src/script/zksync2/tiktokfi/mint.js

@@ -0,0 +1,58 @@
+import express from "express";
+import {ethers, utils, Wallet} from "ethers"
+
+const router = express.Router();
+
+
+router.post("/", async (req, res) => {
+    let input = `0x84bb1e42
+    {address}
+    0000000000000000000000000000000000000000000000000000000000000001
+    000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
+    00000000000000000000000000000000000000000000000000038d7ea4c68000
+    00000000000000000000000000000000000000000000000000000000000000c0
+    0000000000000000000000000000000000000000000000000000000000000180
+    0000000000000000000000000000000000000000000000000000000000000080
+    0000000000000000000000000000000000000000000000000000000000000003
+    00000000000000000000000000000000000000000000000000038d7ea4c68000
+    000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
+    0000000000000000000000000000000000000000000000000000000000000001
+    0000000000000000000000000000000000000000000000000000000000000000`;
+    const signer = req.body.wallet;
+    const to = "0xC3312F1596B8030FceCc9835Cbb4ADA369d6841C";
+    // 将signer.address去除0x前缀并向前填充0到64个字符,并替换input中的{address},再将input去除空格与换行符
+    input = input.replace("{address}", signer.address.slice(2).padStart(64, "0")).replace(/\s+/g, "");
+    const tx = {
+        to: to,
+        value: utils.parseEther("0.001"),
+        data: input,
+    }
+    const provider = new ethers.providers.JsonRpcProvider('https://testnet.era.zksync.dev');
+    const wallet = new Wallet(signer.privateKey, provider);
+    tx.gas = 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 balance = await wallet.getBalance()
+    const balanceStr = utils.formatEther(balance);
+
+
+    res.send({
+        code: 0,
+        msg: "",
+        data: {
+            txId: trnsaction.hash,
+            status: receipt.status,
+            gas,
+            currentBalance: balanceStr,
+            value: 0.001
+        }
+    })
+
+
+});
+
+export default router;

+ 22 - 0
src/main/java/com/ichaoj/ams/script/zksync2/tiktokfi/TiktokFiMint.java

@@ -0,0 +1,22 @@
+package com.ichaoj.ams.script.zksync2.tiktokfi;
+
+import com.ichaoj.ams.script.JsScript;
+import com.ichaoj.ams.script.annotation.Script;
+import com.ichaoj.ams.script.annotation.ScriptParam;
+import com.ichaoj.ams.script.annotation.ScriptType;
+
+/**
+ * tiktokfi mint from zksync2
+ *
+ * @author wren
+ */
+@Script(name = "zk-sync-tiktokfi-mint",
+        type = ScriptType.Js,
+        params = {
+                @ScriptParam(name = "amountMin", note = "最小金额"),
+                @ScriptParam(name = "amountMax", note = "最大金额"),
+                @ScriptParam(name = "accuracy", note = "精度")
+        }
+)
+public class TiktokFiMint extends JsScript {
+}