SophiaTX Developers logo

SDK'S

C# SDK

Alexandria

Alexandria.NET library for SophiaTX blockchain

Table of Contents

Install-DotNetApi

Create Connection-DotNetApi

 protected readonly SophiaClient _client = new SophiaClient(IpAddress, DemonPort, WalletPort); 

Library Functions-DotNetApi

Details-DotNetApi

Get Feed History

_client.Transaction.GetFeedHistory(CurrencySymbol);

Get details about the Blockchain

_client.Transaction.About();

Get a list of functions and How-To available on the sophia blockchain

_client.Transaction.Help();

Get recent transaction and block information on the blockchain

_client.Transaction.Info();

Get block infromation using blockId

_client.Transaction.GetBlock(blockNumber);

Get operations from a block

_client.Transaction.GetOpsInBlock(blockNumber, onlyVirtual);

Get Transaction details

var trx=_client.Transaction.GetTransaction(transactionId);

Keys-DotNetApi

Generate Private Key and Public Key pair

_client.Key.GeneratePrivateKey(new byte[51], new byte[53]);

Get public key using private key

_client.Key.GetPublicKey(privateKey, new byte[53]);

Cryptography-DotNetApi

Encrypt Memo with private key and receiver’s public key for sending secure data across the blockchain

_client.Key.EncryptMemo(memo, PrivateKey, PublicKey2, new byte[1024]);

Decrypt the received using private key and sender’s public key

_client.Key.DecryptMemo(encryptedMemo, PrivateKey2, PublicKey, new byte[1024]);

Send JSON data to list of recepients

var test = "{\"new_book_name\":\"test9999\"}";
           
var data = new SenderData
            {
                AppId = 2,
                PrivateKey = PrivateKey,
                Recipients = new List<string> {accountName1, acocuntName2},
                Sender = accountName,
                JsonDoc = test
            };
            
_client.Data.SendJson(data);

Send plain text to list of recepients

var data = new SenderData
            {
                AppId = 2,
                PrivateKey = PrivateKey,
                Recipients = new List<string> {accountName1, acocuntName2},
                Sender = accountName,
                BinaryDoc = memo
            };
            
_client.Data.SendBinary(data);

Send JSON data to list of recipients asynchronously

var test = "{\"new_book_name\":\"test9999\"}";
           
var data = new SenderData
            {
                AppId = 2,
                PrivateKey = PrivateKey,
                Recipients = new List<string> {accountName1, acocuntName2},
                Sender = accountName,
                JsonDoc = test
            };
            
_client.Data.SendJsonAsync(data);

Send plain text to list of recipients asynchronously

var data = new SenderData
            {
                AppId = 2,
                PrivateKey = PrivateKey,
                Recipients = new List<string> {accountName1, acocuntName2},
                Sender = accountName,
                BinaryDoc = memo
            };
            
_client.Data.SendBinaryAsync(data);

List recieved documents, sorted depending on the search type, start(ISOTimeStamp)

_client.Data.Receive(AppID, accountName, SearchType, start, numberOfEntries);

Accounts-DotNetApi

Create account using private key. Same public key can be used for all three keys required to create accoun.

Seed, can be any unique value string (have atleast 3 digits and no special characters ($, £, #, etc.)) for genrating new account name.

Creator, is an account with enough balance to pay for account creation.

_client.Account.CreateAccount(seed, jsonData, ownerKey, activeKey, memoKey, creator, creatorPrivateKey);

Get account details

_client.Account.GetAccount(accountName);

Delete account

_client.Account.DeleteAccount(accountName, PrivateKey);

Update account keys and JSON details

_client.Account.UpdateAccount(accountName, jsonData, ownerKey, activeKey, memoKey, privateKey);

Get account history

_client.Account.GetAccountHistory(accountName, from, limit);

Get account name from seed (used to create account)

_client.Account.GetAccountNameFromSeed(accountName);

Get account vesting balance

_client.Account.GetVestingBalance(accountName);

Get account balance

_client.Account.GetAccountBalance(accountName);

Check if account still exists

_client.Account.AccountExists(accountName);

Get account authority key

_client.Account.GetActiveAuthority(accountName);

Get account memo key

_client.Account.GetMemoKey(accountName);

Get account owner key

_client.Account.GetOwnerAuthority(accountName);

Create simple multi-signature authority

var pubkeys = new List<string> {publicKey1, publicKey2};
_client.Account.CreateSimpleMultisigAuthority(pubkeys, requiredSignatures);

Create simple managing authority

_client.Account.CreateSimpleManagedAuthority(managingAccountName);

Create simple multi-signature managing authority

var pubkeys = new List<string> {publicKey1, publicKey2};
_client.Account.CreateSimpleMultiManagedAuthority(pubkeys, requiredSignatures);

Transactions-DotNetApi

Transfer amount (argument in the format “250000.00 SPHTX”) from one to other account

_client.Asset.Transfer(accountName, beneficiaryAccountName, amount, memo, privateKey);

Withdraw amount (argument in the format “250000.00 SPHTX”) vesting account balance

_client.Asset.WithdrawVesting(acocuntName, ammount, PrivateKey);

Transfer amount to vesting account

_client.Asset.TransferToVesting(accountName, beneficiaryAccountName, amount, privateKey);

Witnesses-DotNetApi

Get Active Witnesses

_client.Witness.GetActiveWitnesses();

Get List of all witnesses

_client.Witness.ListWitnesses(witnessName, numberOfEntries);

Get details of a witness

_client.Witness.GetWitness(witnessName);

Become a witness, price feed example can be as

var feed1 = new List<PrizeFeedQuoteMessage>
            {
                new PrizeFeedQuoteMessage
                {
                    Currency = "USD",
                    PrizeFeedQuote = new PrizeFeedQuote {Base = "1 USD", Quote = "0.152063 SPHTX"}
                }
                
            };
            var feed2= new List<PrizeFeedQuoteMessage>
            {
                new PrizeFeedQuoteMessage
                {
                    Currency = "EUR",
                    PrizeFeedQuote = new PrizeFeedQuote {Base = "1 EUR", Quote = "0.154988 SPHTX"}
                }
                
            };     
        
var pricefeed=new List<List<PrizeFeedQuoteMessage>>{feed1,feed2};

_client.Witness.UpdateWitness(accountName, url, blockSigningKey, accountCreationFee, minimumBlockSize, pricefeed, privateKey);

Votes-DotNetApi

Set voting proxy

_client.Account.SetVotingProxy(accountName, proxyAccountName, PrivateKey);

Vote for a witness

_client.Witness.VoteForWitness(accountName, witnessName, voteType, privateKey);

Applications-DotNetApi

Create application (the price parameter that specifies billing for the app (1 or 0))

_client.Application.CreateApplication(accountName, applicationName, URL, jsonData, priceParam, PrivateKey);

Update application

_client.Application.UpdateApplication(accountName, applicationName, URL, jsonData, priceParam, PrivateKey);

Delete application

_client.Application.DeleteApplication(accountName, applicationName, PrivateKey);

Buy Application

_client.Application.BuyApplication(accountName, appId, PrivateKey);

Cancel Application purchase

_client.Application.CancelApplicationBuying(sellerAccountName, buyerAccountName, appId, PrivateKey);

Get a list of all bought application and sorting is done depending on search type (bySeller or byBuyer)

_client.Application.GetApplicationBuyings(accountName, SearchType, numberOfEntries);

Get details of list of applications

var names = new List<string>{applicationName1, applicationName2};
_client.Application.GetApplications(names);

Daemon Methods-DotNetApi

Call methods from different Api.

var args = new argumentObject(){};
_client.Transaction.CallPlugin(ApiName,MethodName,args);

Javascript SDK

Alexandria.js

Alexandria.js API library for SophiaTX Blockchain

Table of Contents

Install-JsApi

git clone https://github.com/SophiaTX/Alexandria.js.git
npm install
npm run build
<script src="../dist/alexandria.min.js"></script>

or, use the new updated sophiatx-alexandria-api, npm module to run the project

npm install sophiatx-alexandria-api --save
let sophia=require('sophiatx-alexandria-api');

Connect to http services

sophia.api.setOptions({url: httpConnectionUrl });

Help-JsApi

Get the current version and information about the blockchain

sophia.api.about(function(err, response){
  console.log(err, response);
});

Get the recent updates on the blockchain.

sophia.api.info(function(err, response){
    console.log(err, response);
});

Get help to work with the blockchain, this returns all the method and necessary details about the blockchain its functionalities.

sophia.api.help(function(err, response){
    console.log(err, response);
});

Details-JsApi

Get details about the block using block_id

sophia.api.getBlock(blockNumber,function(err, response){
    console.log(err, response);
});

Get details of operations inside a block

sophia.api.getOpsInBlock(blockNumber,true,function(err, response){
    console.log(err, response);
});

Check if the account still exists

 sophia.api.accountExist(accountName,function(err, response){
     console.log(err, response);
 });

Get transaction history of an account from (-1 means most recent entry) and limit (number of data to be displayed)

 sophia.api.getAccountHistory(accountName,from,limit,function(err, response){
     console.log(err, response);
 });

Get Account History filtered using its type (transfer, transfer_to_vesting, witness_update, account_create, account_delete,account_update, withdraw_vesting, vote, witness_update, transfer_to_vesting, account_witness_vote, account_witness_proxy, custom_json, custom_binary, etc.)

 sophia.api.getAccountHistoryByType(accountName,type,from,limit,function(err, response){
      console.log(err, response);
 });

Get ActiveKey related to the account

 sophia.api.getActiveAuthority(accountName,function(err, response){
     console.log(err, response);
 });

Get MemoKey related to the account

sophia.api.getMemoKey(accountName,function(err, response){
    console.log(err, response);
});

Get OwnerKey related to the account

 sophia.api.getOwnerAuthority(accountName,function(err, response){
     console.log(err, response);
 });

Get account balance of an account

 sophia.api.getAccountBalance(accountName,function(err, response){
     console.log(err, response);
 });

Get account name using the seed(Any data string including uppercase,lowercase and numbers) used to create the account.

 sophia.api.getAccountNameFromSeed(accountName,function(err, response){
      console.log(err, response);
 });

Get vesting balance of the account

 sophia.api.getVestingBalance(accountName,function(err, response){
     console.log(err, response);
 });

Get feed history of the currency using its symbol

   sophia.api.getFeedHistory(symbol,function(err, response){
       console.log(err, response);
   });

Keys-JsApi

Generates separate public key for each of the roles

 console.log(sophia.auth.generateKeys(name,password));

Validates account name whether it can be set or not

 console.log(sophia.utils.validateAccountName(accountName));

Generates public key and private key pair

 console.log(sophia.auth.getPrivateKeys(name,password));

Checks the format of Public key and decides if it is valid with prefix

 console.log(sophia.auth.isPubkey(publicKey,prefix));

Checks the format of Private key and decides if it is valid

 console.log(sophia.auth.isWif(privateKey));

Returns public key on supplied Private key

 console.log(sophia.auth.wifToPublic(privateKey));

Matches public key with private key returns boolean value

 console.log(sophia.auth.wifIsValid(privateKey,publicKey));

Corrects the caps and spaces in distorted passPhrase (brainKey)

 console.log(sophia.auth.normalizeBrainKey(passphrase));

Cryptography-JsApi

Use privateKey of sender’s account and publicKey of receiver’s account to encrypt the message

  console.log(sophia.auth.encrypt(privateKey,publickey,Message));

Use publicKey of sender’s account and privateKey of receiver’s account to decrypt the message

  console.log(sophia.auth.decrypt(privateKey,publicKey,EncryptedMessage));

Accounts-JsApi

Create account using seed(Any data string including uppercase,lowercase and numbers), creator as Witness’s name, Witness’s PrivateKey and user’s PublicKey as ActiveKey

 sophia.api.createAccount(creatorName,seed,creatorPrivateKey,json_meta, owner, active, memo_key,function(err,response){
     console.log(err,response);
 });

Delete account using user’s PrivateKey

 sophia.api.deleteAccount(accountName,privateKey,function(err,response){
     console.log(err,response);
 });

Update ActiveKey, OwnerKey, MemoKey and JsonMetadata of the account using user’s PrivateKey

 sophia.api.updateAccount(accountName,jsonMeta,owner,active, memoKey,privateKey,function(err,response){
     console.log(err,response);
 });

Get account details

 sophia.api.getAccount(accountName, function(err, response){
     console.log(err, response);
 });

Sponsor an account, isSponsored is a boolean value to enable and disable the sponsorship

  sophia.api.sponsorAccountFees(sponsor,sponsored,isSponsored,privateKey,function(err, response){
       console.log(err, response);
  });

Transaction-JsApi

Transfer an amount (in the form of “amount (space) currencySymbol, 10.000 SPHTX”) to other account with a memo (receipt/details) attached to the transfer using Sender’s Priavtekey.

 sophia.api.transfer(from, to, amount, memo,privateKey,function(err,response){
     console.log(err,response);
 });

Get transaction id using transaction object as an argument.

   console.log(sophia.api.getTransactionId(transaction));

Transfer amount (in the form of “amount currencySymbol, 10.000 SPHTX”) to Vesting.

  sophia.api.transferToVesting(from, to, amount,privateKey,function(err,response){
      console.log(err,response);
  });

Withdraw amount (in the form of “amount currencySymbol, 10.000 SPHTX”) from Vesting in fractions.

  sophia.api.withdrawVesting(from,vestingShares,privateKey,function(err,response){
      console.log(err,response);
  });

Get transaction details using transaction id

  sophia.api.getTransaction(transactionId,function(err, response){
       console.log(err, response);
  });

Witness-JsApi

Get list of Witnesses or miners

sophia.api.listWitnesses(startFromWitnessName,count,function(err, response){
    console.log(err, response);
});

Get list of Witnesses by votes in descending order

sophia.api.listWitnessesByVote(startFromWitnessName,count,function(err, response){
    console.log(err, response);
});

Get details about a Witness

sophia.api.getWitness(witnessName,function(err, response){
    console.log(err, response);
});

Update witness is the function to update an existing account as a witness contender it needs prize feed update as an argument, prizeFeed example ([["USD",{"base":"1 USD","quote":"0.187331 SPHTX"}]]) can be used for testing, blockSigningKey (publicKey format) is used to sign all the blocks. It also needs a description url, where the willing user can put detail about herself. To become a witness the user must have at least 250,000 SPHTX tokens in her vesting account.

  sophia.api.updateWitness(accountName, descriptionUrl, blockSigningKey, accountCreationFee, maximumBlockSizeLimit, prizeFeed, privateKey,function(err,response){
  console.log(err,response);
  });

Voting-JsApi

Set a proxy account for doing votes on behalf of first account.

 sophia.api.setVotingProxy(accountToModify, proxy,privateKey,function(err,response){
     console.log(err,response);
 });

Vote for a witness using witness name and voter’s PrivateKey

 sophia.api.voteForWitness(accountToVoteWith, accountToVoteFor, approve=true,privateKey,function(err,response){
     console.log(err,response);
 });

Data Transmission-JsApi

Get the list of received documents, it can be searched by by_sender, by_recipient,by_sender_datetime,by_recipient_datetime.

  sophia.api.getReceivedDocuments(appId, accountName, searchType, start, count, function(err,response){
     console.log(err,response);
  });

Send binary data to the list of recipients (Secured/Encoded data could be transmitted using this function).

 sophia.api.makeCustomBinaryOperation(appId, from, to, data, privateKey, function(err,response){
     console.log(err,response);
 });

Send JSON data to the list of recipients.

 sophia.api.makeCustomJSONOperation(appId, from, to, data, privateKey, function(err,response){
    console.log(err,response);
 });

Daemon Methods-JsApi

Run other endpoint methods

 sophia.api.callPlugin(pluginName,methodName,arguments,function(err, response){
      console.log(err, response);
  });