finalSymbolFacadefacade=newSymbolFacade("mainnet");System.out.println("Network name: "+facade.network.name);// NetworkTimestamp(0) is the genesis block timestampfinalInstantlaunchDate=facade.network.toDatetime(newNetworkTimestamp(0));System.out.println("Network launch date: "+launchDate);
The class is the main entry point to the Symbol SDK.
It provides most of the methods you will need when working with Symbol:
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.
NODE_URL='https://whydah.symbolmain.net:3001'print(f'Using node {NODE_URL}')try:# Fetch current chain informationinfo_path='/chain/info'print(f'Fetching chain information from {info_path}')withurllib.request.urlopen(f'{NODE_URL}{info_path}',timeout=10)asresponse:response_json=json.loads(response.read().decode())height=int(response_json['height'])print(f" Blockchain height: {height:,} blocks")excepturllib.error.URLErrorase:print(e.reason)
finalStringnodeUrl="https://whydah.symbolmain.net:3001";System.out.println("Using node "+nodeUrl);// Fetch current chain informationfinalStringinfoPath="/chain/info";System.out.println("Fetching chain information from "+infoPath);finalHttpClientclient=HttpClient.newHttpClient();finalHttpRequestrequest=HttpRequest.newBuilder(URI.create(nodeUrl+infoPath)).timeout(Duration.ofSeconds(10)).GET().build();finalHttpResponse<String>response=client.send(request,BodyHandlers.ofString());finalJsonNoderesponseJson=newObjectMapper().readTree(response.body());finallongheight=responseJson.get("height").asLong();System.out.printf(" Blockchain height: %,d blocks%n",height);
Interaction with the Symbol blockchain happens through API nodes, which expose a REST interface for
querying network state and submitting transactions.
Not all nodes provide this interface, so it is important to connect to one labeled as API Node.
This example connects to an API node and retrieves the current blockchain height from the /chain/infoGET 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.