Skip to content

SophiaTX/Alexandria-API-JavaScript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alexandria.js

Alexandria.js API library for SophiaTX Blockchain

Table of Contents

Install

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

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

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

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

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

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

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

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

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

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

Run other endpoint methods

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published