Published 8 July 2019

Examples: JS: Connect by API

 

In this example all interactions with Credits API will be implemented in the class CreditsUtils

The example describes how to connect to and disconnect from the Credits API 

Connection parameters, wallet keys and destination address are shared in the constructor

class CreditsUtils {

   constructor(publicKey, privateKey, targetKey, url) {

       this.publicKey = publicKey;

       this.privateKey = privateKey;

       this.targetKey = targetKey;

       this.url = url;

       this.publicKeyByte = from_b58(this.publicKey);

       this.privateKeyByte = from_b58(this.privateKey);

       this.targetKeyByte = from_b58(this.targetKey);

   }

   client() {

       var transport = new Thrift.Transport(this.url);

       var protocol = new Thrift.Protocol(transport);

       return new APIClient(protocol);

   }

}

Usage

   <script>

       function run()

       {

           var pubkey = "your public key";

           var prvkey = "your private key";

           var trgKey = "your target key";

           var url = "http://127.0.0.1:8081";

           var client = new CreditsUtils(pubkey, prvkey, trgKey, url);

       }

   </script>

Votes 0, average rating 0

Contents