Kaynağa Gözat

优化gas费价格

wkw 1 hafta önce
ebeveyn
işleme
964a920f4c
1 değiştirilmiş dosya ile 6 ekleme ve 5 silme
  1. 6 5
      src/utils/web.js

+ 6 - 5
src/utils/web.js

@@ -49,7 +49,8 @@ async function sendSingleReward(privateKey, amount) {
         const amountWei = web3.utils.toWei(amount.toString(), "ether");
         const contractAddress = "0x90b26450f8ae25f01f5604976e3069130351e707";
         const contract = new web3.eth.Contract(jlabiData, contractAddress);
-
+        let gasPrice = await web3.eth.getGasPrice();
+        gasPrice = (BigInt(gasPrice) * 10n).toString();
         const { timestamp, nonceForSig, signature } = await buildSignatureParams(sender, amountWei, contractAddress);
 
         if (!signature) throw new Error("签名为空");
@@ -61,7 +62,7 @@ async function sendSingleReward(privateKey, amount) {
                 .distributeSingleReward(sender, amountWei, timestamp, nonceForSig, signature)
                 .encodeABI(),
             gas: 500000,
-            gasPrice: await web3.eth.getGasPrice(),
+            gasPrice,
             nonce: await web3.eth.getTransactionCount(sender, "pending"),
             chainId: await web3.eth.getChainId()
         };
@@ -88,10 +89,10 @@ async function tokenSignUp(privateKey, amount, type) {
         const tokenAmount = web3.utils.toWei(amount.toString(), "ether");
         const account = web3.eth.accounts.privateKeyToAccount(privateKey);
         const sender = account.address;
-
-        const [chainId, gasPrice, nonce] = await Promise.all([
+        let gasPrice = await web3.eth.getGasPrice();
+        gasPrice = (BigInt(gasPrice) * 10n).toString();
+        const [chainId, nonce] = await Promise.all([
             web3.eth.getChainId(),
-            web3.eth.getGasPrice(),
             web3.eth.getTransactionCount(sender)
         ]);