|
@@ -0,0 +1,45 @@
|
|
|
+package com.ichaoj.ams.script.transfer;
|
|
|
+
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
+import com.ichaoj.ams.script.IScript;
|
|
|
+import com.ichaoj.ams.script.SResult;
|
|
|
+import com.ichaoj.ams.script.annotation.Script;
|
|
|
+import com.ichaoj.ams.script.annotation.ScriptParam;
|
|
|
+import com.ichaoj.ams.script.model.AirdropParam;
|
|
|
+import com.ichaoj.ams.script.model.AirdropWallet;
|
|
|
+import com.ichaoj.ams.script.util.Web3Util;
|
|
|
+import lombok.SneakyThrows;
|
|
|
+import org.web3j.crypto.RawTransaction;
|
|
|
+import org.web3j.protocol.Web3j;
|
|
|
+import org.web3j.protocol.http.HttpService;
|
|
|
+import org.web3j.utils.Convert;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.BigInteger;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author wren
|
|
|
+ */
|
|
|
+@Script(name = "transfer-test",
|
|
|
+ params = {
|
|
|
+ @ScriptParam(name = "minAmount", note = "转账最小金额", defaultValue = "0.001"),
|
|
|
+ @ScriptParam(name = "maxAmount", note = "转账最大金额", defaultValue = "0.002"),
|
|
|
+ @ScriptParam(name = "accuracy", note = "转账精度(精确到小数点后几位)", defaultValue = "5")
|
|
|
+ }
|
|
|
+)
|
|
|
+public class TransferScript extends IScript {
|
|
|
+ @SneakyThrows
|
|
|
+ @Override
|
|
|
+ public SResult run(Map<String, AirdropParam> params, AirdropWallet airdropWallet) {
|
|
|
+ Web3j web3j = Web3j.build(new HttpService("https://eth-sepolia.g.alchemy.com/v2/QR461hv0kEkKn91VlTAlIx6RhnnfPl-m"));
|
|
|
+ BigInteger nonce = Web3Util.getNonce(web3j, airdropWallet.getAddress());
|
|
|
+ BigInteger gasPrice = web3j.ethGasPrice().send().getGasPrice();
|
|
|
+ BigDecimal randomed = RandomUtil.randomBigDecimal(new BigDecimal(params.get("minAmount").getValue()), new BigDecimal(params.get("maxAmount").getValue()));
|
|
|
+ randomed = randomed.setScale(Integer.parseInt(params.get("accuracy").getValue()), RoundingMode.DOWN);
|
|
|
+ RawTransaction etherTransaction = RawTransaction.createEtherTransaction(nonce, gasPrice, BigInteger.valueOf(21000), "0x0870682e56A9069E7655afD728D91f3653Bff0bE", Convert.toWei(randomed.toString(), Convert.Unit.ETHER).toBigInteger());
|
|
|
+ return sendTx(airdropWallet, web3j, etherTransaction);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|