|
| 1 | +package com.concordium.sdk.examples; |
| 2 | + |
| 3 | +import com.concordium.sdk.ClientV2; |
| 4 | +import com.concordium.sdk.Connection; |
| 5 | +import com.concordium.sdk.crypto.ed25519.ED25519SecretKey; |
| 6 | +import com.concordium.sdk.exceptions.ClientInitializationException; |
| 7 | +import com.concordium.sdk.requests.AccountQuery; |
| 8 | +import com.concordium.sdk.requests.BlockQuery; |
| 9 | +import com.concordium.sdk.responses.blockitemstatus.FinalizedBlockItem; |
| 10 | +import com.concordium.sdk.transactions.*; |
| 11 | +import com.concordium.sdk.transactions.tokens.TokenOperationAmount; |
| 12 | +import com.concordium.sdk.transactions.tokens.MintTokenOperation; |
| 13 | +import com.concordium.sdk.types.AccountAddress; |
| 14 | +import lombok.var; |
| 15 | +import picocli.CommandLine; |
| 16 | +import picocli.CommandLine.Command; |
| 17 | +import picocli.CommandLine.Option; |
| 18 | + |
| 19 | +import java.math.BigDecimal; |
| 20 | +import java.net.MalformedURLException; |
| 21 | +import java.net.URL; |
| 22 | +import java.util.Optional; |
| 23 | +import java.util.concurrent.Callable; |
| 24 | + |
| 25 | +@Command(name = "MintToken", mixinStandardHelpOptions = true) |
| 26 | +public class MintToken implements Callable<Integer> { |
| 27 | + @Option( |
| 28 | + names = {"--endpoint"}, |
| 29 | + description = "GRPC interface of the node.", |
| 30 | + defaultValue = "https://127.0.0.1:7000") |
| 31 | + private String endpoint; |
| 32 | + |
| 33 | + @Option( |
| 34 | + names = {"--timeout"}, |
| 35 | + description = "GRPC request timeout in milliseconds.", |
| 36 | + defaultValue = "100000") |
| 37 | + private int timeout; |
| 38 | + |
| 39 | + @Override |
| 40 | + public Integer call() throws MalformedURLException, ClientInitializationException { |
| 41 | + var endpointUrl = new URL(this.endpoint); |
| 42 | + |
| 43 | + Connection connection = Connection.newBuilder() |
| 44 | + .host(endpointUrl.getHost()) |
| 45 | + .port(endpointUrl.getPort()) |
| 46 | + //.useTLS(TLSConfig.auto()) //update this as necessary if using tls or not |
| 47 | + .build(); |
| 48 | + |
| 49 | + String tokenSymbol = "RRR10"; // Replace this with the appropriate token symbol in your node |
| 50 | + TokenOperationAmount amount = new TokenOperationAmount( |
| 51 | + new BigDecimal("1"), |
| 52 | + 6 //ensure the decimal precision here matches the value of the decimal during token creation |
| 53 | + ); |
| 54 | + |
| 55 | + //use an address valid in the node being used |
| 56 | + AccountAddress sender = AccountAddress.from("4FbFhx5C5XaSUKdnTdrRVbtNW6rtgYYdKRJtggYGBSiktiymsX"); |
| 57 | + Expiry expiry = Expiry.createNew().addMinutes(5); |
| 58 | + |
| 59 | + //replace with a valid sign key value from the accounts of the node being used |
| 60 | + TransactionSigner signer = TransactionSigner.from( |
| 61 | + SignerEntry.from(Index.from(0), Index.from(0), |
| 62 | + ED25519SecretKey |
| 63 | + .from("b4cef1510079ba946c093826d3cf9cdd3132fa9dd8aaaf9c01442bf12d6614fd"))); |
| 64 | + |
| 65 | + var client = ClientV2.from(connection); |
| 66 | + var senderInfo = client.getAccountInfo(BlockQuery.BEST, AccountQuery.from(sender)); |
| 67 | + var nonce = senderInfo.getNonce(); |
| 68 | + var txnHash = client.sendTransaction( |
| 69 | + TransactionFactory |
| 70 | + .newTokenUpdate( TokenUpdate |
| 71 | + .builder() |
| 72 | + .tokenSymbol(tokenSymbol) |
| 73 | + .operation( |
| 74 | + MintTokenOperation |
| 75 | + .builder() |
| 76 | + .amount(amount) |
| 77 | + .build() |
| 78 | + ).build() |
| 79 | + ) |
| 80 | + .nonce(nonce) |
| 81 | + .expiry(expiry) |
| 82 | + .sender(sender) |
| 83 | + .sign(signer) |
| 84 | + ); |
| 85 | + System.out.println(txnHash); |
| 86 | + Optional<FinalizedBlockItem> finalizedBlockItem = client.waitUntilFinalized(txnHash, this.timeout); |
| 87 | + System.out.println(finalizedBlockItem); |
| 88 | + return 0; |
| 89 | + } |
| 90 | + |
| 91 | + public static void main(String[] args) { |
| 92 | + int exitCode = new CommandLine(new MintToken()).execute(args); |
| 93 | + System.exit(exitCode); |
| 94 | + } |
| 95 | +} |
0 commit comments