public boolean mintNFTByAmount(Web3j web3j, String contractAddress, int amount) {
if (web3j == null) return false;
String methodName = "mint";
String fromAddr = emptyAddress;
Function function = new Function(
methodName,
Arrays.asList(new Uint256(amount)),
Arrays.asList(new TypeReference() {
}));
String data = FunctionEncoder.encode(function);
Transaction transaction = Transaction.createEthCallTransaction(fromAddr, contractAddress, data);
EthCall ethCall;
try {
ethCall = web3j.ethCall(transaction, DefaultBlockParameterName.LATEST).sendAsync().get();
//List<Type> results = FunctionReturnDecoder.decode(ethCall.getValue(), function.getOutputParameters());
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
return true;
}
/**
* 调用NFT的Mint方法根据合约有两种
* Function: mint(address _to, uint256 _mintAmount)
***/
public boolean mintNFTByAmountAndAddress(Web3j web3j, Credentials credentials, String contractAddress, int amount) {
if (web3j == null) return false;
if (credentials == null) return false;
String methodName = "mint";
String fromAddr = emptyAddress;
Function function = new Function(
methodName,
Arrays.asList(new Address(credentials.getAddress()), new Uint256(amount)),
Arrays.asList(new TypeReference<Type>() {
}));
String data = FunctionEncoder.encode(function);
Transaction transaction = Transaction.createEthCallTransaction(fromAddr, contractAddress, data);
EthCall ethCall;
try {
ethCall = web3j.ethCall(transaction, DefaultBlockParameterName.LATEST).sendAsync().get();
//List<Type> results = FunctionReturnDecoder.decode(ethCall.getValue(), function.getOutputParameters());
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
return true;
}
have some problem for contract 721