|
@@ -0,0 +1,73 @@
|
|
|
|
+import express from "express";
|
|
|
|
+import {ethers, utils, Wallet} from "ethers"
|
|
|
|
+
|
|
|
|
+const router = express.Router();
|
|
|
|
+
|
|
|
|
+// 0x84bb1e42
|
|
|
|
+// 000000000000000000000000368715f09c1ab5e0b55bf5ba19cd887189a28dbe
|
|
|
|
+// 0000000000000000000000000000000000000000000000000000000000000001
|
|
|
|
+// 000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
|
|
|
+// 00000000000000000000000000000000000000000000000000038d7ea4c68000
|
|
|
|
+// 00000000000000000000000000000000000000000000000000000000000000c0
|
|
|
|
+// 0000000000000000000000000000000000000000000000000000000000000180
|
|
|
|
+// 0000000000000000000000000000000000000000000000000000000000000080
|
|
|
|
+// 0000000000000000000000000000000000000000000000000000000000000003
|
|
|
|
+// 00000000000000000000000000000000000000000000000000038d7ea4c68000
|
|
|
|
+// 000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
|
|
|
+// 0000000000000000000000000000000000000000000000000000000000000001
|
|
|
|
+// 0000000000000000000000000000000000000000000000000000000000000000
|
|
|
|
+// 0000000000000000000000000000000000000000000000000000000000000000
|
|
|
|
+router.post("/", async (req, res) => {
|
|
|
|
+ let input = `0x84bb1e42
|
|
|
|
+ {address}
|
|
|
|
+ 0000000000000000000000000000000000000000000000000000000000000001
|
|
|
|
+ 000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
|
|
|
+ 00000000000000000000000000000000000000000000000000038d7ea4c68000
|
|
|
|
+ 00000000000000000000000000000000000000000000000000000000000000c0
|
|
|
|
+ 0000000000000000000000000000000000000000000000000000000000000180
|
|
|
|
+ 0000000000000000000000000000000000000000000000000000000000000080
|
|
|
|
+ 0000000000000000000000000000000000000000000000000000000000000003
|
|
|
|
+ 00000000000000000000000000000000000000000000000000038d7ea4c68000
|
|
|
|
+ 000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
|
|
|
|
+ 0000000000000000000000000000000000000000000000000000000000000001
|
|
|
|
+ 0000000000000000000000000000000000000000000000000000000000000000
|
|
|
|
+ 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://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 tran = await provider.getTransaction(trnsaction.hash);
|
|
|
|
+ const gas = utils.formatEther(receipt.gasUsed * tran.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;
|