Published 28 June 2019

Examples: C#: Connect by API

Project:

https://github.com/CREDITSCOM/examples.git

Branch:

https://github.com/CREDITSCOM/examples/tree/master/API/CreditsCSharpDemo

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

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 Client : IDisposable

   {    

        TSocket transport;

        TBinaryProtocol protocol;

        API.Client api;

        public Keys keys;

        public Client(string ip, int port, string publicKey, string privateKey, string targetKey)

        {         

            transport = new TSocket(ip, port);

            protocol = new TBinaryProtocol(transport);

            api = new API.Client(protocol);

            transport.Open();

            keys = new Keys();

            keys.PublicKey = publicKey;

            keys.PrivateKey = privateKey;

            keys.TargetKey = targetKey;

       }     

       public void Dispose()

       { 

            transport.Close();

       }

       // ...

}

Usage

        static void Main(string[] args)

        {         

            Console.WriteLine("Credits API Simple Demo");

            if(args.Length != 5)

            {            

                Console.WriteLine("Usage: CreditsCSAPIDemo NodeIpAddress NodePort YourPublicKey YourPrivateKey TargetPublicKey");

                return;

            }

            using (var client = new Client(args[0], Convert.ToInt32(args[1]), args[2], args[3], args[4]))

            {           

               // your place your code

            }

            Console.WriteLine("Press [Enter] to exit...");

            Console.ReadLine();

}        

Votes 0, average rating 0

Contents