lisk-docs icon indicating copy to clipboard operation
lisk-docs copied to clipboard

How to connect to a remote Lisk node with a frontend

Open Tschakki opened this issue 3 years ago • 0 comments

What

https://lisk.com/documentation/lisk-sdk/guides/app-development/frontend.html

How

Add example to frontend guide: How to connect to a remote Lisk node with a frontend

Additional information

If you are using latest version of the sdk. There is no rpc.public attribute. Also you have to set rpc.host to 0.0.0.0 to allow connections on all IPs not just 127.0.0.1. I just did a quick test and it works fine.

<html>
  <head> </head>
  <body>
    <span id=""info""></span>
  </body>
  <script src=""https://js.lisk.io/lisk-client-5.1.3.js""></script>
  <script defer>
    async function run() {
      try {
        const client = await lisk.apiClient.createWSClient(
          ""ws://192.168.1.201:9999/ws""
        );
        const nodeInfo = await client.node.getNodeInfo();
        document.getElementById(""info"").innerHTML = JSON.stringify(nodeInfo);
      } catch (err) {
        console.error(err);
      }
    }
    run();
  </script>
</html>

Tschakki avatar Nov 10 '21 14:11 Tschakki