finalNemFacadefacade=newNemFacade("testnet");System.out.println("Network name: "+facade.network.name);// NetworkTimestamp(0) is the genesis block timestamp// (network launch)finalInstantlaunchDate=facade.network.toDatetime(newNetworkTimestamp(0));System.out.println("Network launch date: "+launchDate);
The class is the main entry point to the Symbol SDK when working with the NEM blockchain.
It provides most of the methods you will need, from building and signing transactions to retrieving network-related
information.
To create a facade, simply specify the name of the network you want to work with, either mainnet or testnet.
This example then demonstrates how to retrieve the network launch date.
The method converts a network timestamp into a UTC datetime.
By passing 0 (the genesis timestamp) you can obtain the moment the genesis block was produced, that is, the network's
launch date.
finalStringnodeUrl="http://libertalia.nemtest.net:7890";System.out.println("Using node "+nodeUrl);// Fetch current chain heightfinalStringheightPath="/chain/height";System.out.println("Fetching chain height from "+heightPath);finalHttpRequestrequest=HttpRequest.newBuilder(URI.create(nodeUrl+heightPath)).timeout(Duration.ofSeconds(10)).GET().build();finalHttpResponse<String>response=HttpClient.newHttpClient().send(request,BodyHandlers.ofString());if(200!=response.statusCode())thrownewIOException("HTTP error! status: "+response.statusCode());finalJsonNoderesponseJson=newObjectMapper().readTree(response.body());finallongheight=responseJson.get("height").asLong();System.out.printf(" Blockchain height: %,d blocks%n",height);
Interaction with the NEM blockchain happens through a node, which exposes a REST interface for querying network
state and submitting transactions.
This example connects to a testnet node and retrieves the current blockchain height from the /chain/heightGET
endpoint.
This request does not require any private keys or authorization, making it a simple and effective test to confirm that
the environment is set up correctly and can reach the network.