这里的java代码要配合部署的归集合约才可以实现
这里只做展示效果
// TODO: 这三步需要分步进行
public static void main(String[] args) throws IOException {
List<String> fromAddressList = new ArrayList<>();
JSONArray jsonArray = getPrivateKey();
// TODO: 1.授权时需要挨个扣手续费
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String address = jsonObject.getString("address");
String privateKey = jsonObject.getString("privateKey");
// TODO: 授权合约
approve(address, privateKey);
fromAddressList.add(address);
}
// TODO: 2.查询不需要扣手续费,如果上面执行成功了,这一步能查询到授权金额就是成功了
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
String address = jsonObject.getString("address");
String privateKey = jsonObject.getString("privateKey");
// TODO: 查询授权额度
allow(address, privateKey);
}
List<BigInteger> value = new ArrayList<>();
for (String selectaddress : fromAddressList) {
BigInteger amount = new BigInteger(getERC20Balance(selectaddress, coinAddress).substring(2), 16);
value.add(amount);
}
System.out.println(fromAddressList);
System.out.println(value);
// TODO: 3.批量归集
signTokenTransactionList(fromAddressList, value, mainAddress, mainPrivatekey);
}
测试网效果图