Skip to content

Commit b25832e

Browse files
authored
Update CreateTokenDemo.java
Signed-off-by: SimiHunjan <simi.hunjan.k@gmail.com>
1 parent 939b595 commit b25832e

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

.github/examples/java/CreateTokenDemo.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,25 @@
99

1010
public class CreateTokenDemo {
1111
public static void main(String[] args ) throws Exception {
12-
// load your operator credentials
13-
AccountId operatorId = AccountId.fromString(System.getenv("OPERATOR_ID"));
14-
PrivateKey operatorKey = PrivateKey.fromString(System.getenv("OPERATOR_KEY"));
12+
// .env-provided
13+
String operatorId = System.getenv("OPERATOR_ID");
14+
String operatorKey = System.getenv("OPERATOR_KEY");
15+
String network = System.getenv().getOrDefault("HEDERA_NETWORK", "local"); // "local" for Solo
16+
String mirrorNodeUrl = System.getenv().getOrDefault(
17+
"MIRROR_NODE_URL",
18+
"http://localhost:5551/api/v1" // Solo default (adjust if yours differs)
19+
);
1520

16-
// initialize the client for testnet
17-
Client client = Client.forTestnet().setOperator(operatorId, operatorKey);
21+
if (operatorId == null || operatorKey == null) {
22+
throw new IllegalStateException("OPERATOR_ID / OPERATOR_KEY not set");
23+
}
24+
25+
Client client =
26+
"local".equalsIgnoreCase(network)
27+
? Client.forNetwork(java.util.Map.of("127.0.0.1:50211", new AccountId(3))) // Solo default node + node account (adjust if needed)
28+
: Client.forTestnet();
29+
30+
client.setOperator(AccountId.fromString(operatorId), PrivateKey.fromString(operatorKey));
1831

1932
// generate token keys
2033
PrivateKey supplyKey = PrivateKey.generateECDSA();

0 commit comments

Comments
 (0)