Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in Blockchain by (12.7k points)

How to push transactions dynamically into the run method of the hash graph?

For instance: In the below code, the name is published as a transaction. How to get this value dynamically. If it has to be through a socket, which is the best place to initiate the socket?

public void run() {

 String myName = platform.getState().getAddressBookCopy().getAddress(selfId).getSelfName();

    console.out.println("Hello Swirld from " + myName);

    byte[] transaction = myName.getBytes(StandardCharsets.UTF_8);

    platform.createTransaction(transaction, null);

    String lastReceived = "";

    while (true) {

        IPOSAppState state = (IPOSAppState) platform.getState();

        String received = state.getReceived();

        if (!lastReceived.equals(received)) {

            lastReceived = received;

            console.out.println("Received: " + received); // print all received transactions


       try {


        } catch (Exception e) {




Any example code would really help.

1 Answer

0 votes
by (29.5k points)

Hi, you can refernce the project link i am mentioning below, it contains a demonstration of a web application communicating with a Swirld sdk.

Browse Categories