0%

Java×以太坊 批量铸造X1测试网代币OKB

我之前写了一篇文章介绍过X1测试网:https://blog.120.show/2023/28/

现在是为了更加方便来研究,比如自动铸造OKB测试币。

我们研究了一下,其实就是一个转账操作,然后携带了数据(触发了方法)。过程中遇到了因为gas Limit设置太低而导致的失败。因为我是从其他地方复制的代码,他里面设置的是3万,实际上可能需要7万左右。

合约的地址:0xf875fEcfF122927E53C3b07F4258C690b026004b

转账的数据为:0x40c10f190000000000000000000000003f4b6664338f23d2397c953f2ab4ce8031663f800000000000000000000000000000000000000000000000008ac7230489e80000

所以,我写成了以下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package sepolia;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.methods.response.EthSendTransaction;
import org.web3j.protocol.http.HttpService;
import org.web3j.tx.RawTransactionManager;
import utlis.urlNet;
import utlis.walletUtils;
import java.io.IOException;
import java.math.BigInteger;
/**
* @author HMB-XS
* @date 2023年12月25日10:44:19
**/
public class OneCode {
public static void main(String[] args) throws IOException {
// 初始化web3j客户端
Web3j web3 = Web3j.build(new HttpService(urlNet.sepoliaInfura));
// 获取钱包对象
Credentials credentials = walletUtils.testKeyBig();
// 合约地址
String address = "0xf875fEcfF122927E53C3b07F4258C690b026004b";
// 写入内容
String dataOKB = "0x40c10f190000000000000000000000003f4b6664338f23d2397c953f2ab4ce8031663f800000000000000000000000000000000000000000000000008ac7230489e80000";
// 获取当前网络的建议费用
BigInteger maxPriorityFeePerGas = web3.ethGasPrice().send().getGasPrice();
BigInteger maxFeePerGas = maxPriorityFeePerGas.add(BigInteger.valueOf(3000000000L));// 加30Gwei
for(int i = 0; i < 50000;i++) {
try {
// 构建交易对象
EthSendTransaction ethSendTransaction = new RawTransactionManager(
web3, credentials)
.sendEIP1559Transaction(
urlNet.sepoliaChainId,
maxPriorityFeePerGas, // 优先级
maxFeePerGas, // 最大费用
BigInteger.valueOf(102184L),// gasLimit 手动调整
address,
dataOKB,
BigInteger.ZERO
);
String transactionHash = ethSendTransaction.getTransactionHash();
System.out.println("[" + i + "] " + transactionHash);
} catch (Exception e) {
System.out.println("本次运行遇到异常,默认不处理。");
}
}
}
}

上面的代码有三处要修改一下:

urlNet.sepoliaInfura 这是我的静态资源,请换成你的infura或者其他RPC节点信息。

urlNet.sepoliaChainId 是11155111。

Credentials credentials = walletUtils.testKeyBig();这是我写的一个快捷生成方式,请替换为下面的代码。

1
Credentials credentials = Credentials.create("私钥");

然后就可以运行代码了。

image-20231225214200468

公共节点可能平均要好几次才成功一次,私有的节点(注册账号)基本上都可以成功。

然后就可以看到OKB测试币的数量蹭蹭的往上涨。

image-20231225214547032

不一会儿就几万个OKB测试币了。

速度嘎嘎的快。

果然科技才是第一生产力。