hedera-services

1.0.40 • Public • Published

hedera-services

This microservice is created to connect any frontend or backend application to hedera block chain network.

This package will help users to create NFTs in batch & Transfer ownership of NFT to other users.

Note: Creating NFTs in batch saves the GAS amount charged per NFT creation. Currently for each NFT creation hedera charges around 14 HBARs as GAS cost. With batch NFTs creation you can create around 1,000 NFTs with same GAS cost as 1 NFT i.e around 14 HBARs.

Not only NFTs but this package will also help to create custom fungible tokens on hedera network with capability of transferring it to multiple users withing hedera eco system.

This package will also help to swap custom fungible tokens to HBARs & vice versa.

Getting started

  1. Install package using command npm install hedera-services

  2. Initialise and Get the the Client as follow:

     const initClient = async (
         operatorId,
         operatorPvKey,
         maxQueryPayment,
         isMainNet = false
     ) => {
         try {
             const client = await getClient(           
                 operatorId,
                 operatorPvKey,
                 maxQueryPayment,
                 isMainNet
             );  
             global.client;
             global.client = client;
         } catch (error) {
             throw error;
         }
     };
    
  3. Non Fungible Token:

    A. To create new NFTs:

     createAndMintToken(
         "<token_name>", //string
         "<token_symbol>", //string(max 3 characters)
         "<nft_owner_account_id>", //string
         "<nft_owner_account_private_key>"  //string
         "<nft_meta_data>" //array of buffered string
     );
    

    B. To create new NFTs with limited supply

     mintFiniteNFTs(
         "<token_name>", //string
         "<token_symbol>", //string(max 3 characters)
         "<nft_owner_account_id>", //string
         "<nft_owner_account_private_key>"  //string
         "<nft_meta_data>", //array of buffered string
         "<max_supply>", //integer
     )
    

    C. To create non fungible token

     createNonFungibleToken(
         tokenName, 
         "<token_name>", //string
         "<token_symbol>", //string(max 3 characters)
         "<account_id>", //string 
         "<account_private_key>", //string
     )
    

    D. To mint non fungible token

     mintNonFungibleToken(
         "<token_id>", //string
         "<account_id>", //string 
         "<account_private_key>", //string 
         "<metadata>", //array of buffered string 
     )
    

    E. To transfer NFT ownership:

     purchaseNFT(
         "<nft_token_id>", //string 
         "<nft_sell_price>", //int (in TinyBars)
         "<new_owner_account_id>", //string
         "<new_owner_private_key>" //string
         "<existing_owner_account_id>" //string
         "<existing_owner_private_key>", //string
         "<serial_no>" //int (to trnasfer specific NFT from batch, provide selected NFT serial number. you can get the serial   number of NFT from hedera mirror nodes api)
     );
    

    F. To transfer NFT with Royalty:

     purchaseNFT(
         "<nft_token_id>", // string 
         "<nft_sell_price>", // int (in TinyBars)
         "<new_owner_account_id>", // string
         "<new_owner_private_key>" // string
         "<existing_owner_account_id>" // string
         "<existing_owner_private_key>", // string
         "<serial_no>" // int (to trnasfer specific NFT from batch, provide selected NFT serial number. you can get the serial number of NFT from hedera mirror nodes api)
         "<royaltyPercentage>", // int
         "<creatorAccount>" // string
     );
    

    G: To tansfer NFT using Fungible token

     purchaseNFTUsingToken(
         "<tokenId>", // string
         "<sellPrice>", // int
         "<serialNumber>", // int
         "<fungibleToken>", // string
         "<buyerAccount>", // string
         "<buyerPvKey>", // string
         "<sellerAccount>", // string
         "<sellerPvKey>", // string
     )
    

    H: To tansfer NFT using fungible token with royalty

     purchaseNFTUsingToken(
         "<tokenId>", // string
         "<sellPrice>", // int
         "<serialNumber>", // int
         "<fungibleToken>", // string
         "<buyerAccount>", // string
         "<buyerPvKey>", // string
         "<sellerAccount>", // string
         "<sellerPvKey>", // string
         "<royaltyPercentage>", // int
         "<creatorAccount>", // string
     )
    

    I. To transfer multiple NFTs:

     transferMultipleNFTs(
         "<nft_token_id>", //string 
         "<nft_sell_price>", //int (in TinyBars)
         "<new_owner_account_id>", //string
         "<new_owner_private_key>" //string
         "<existing_owner_account_id>" //string
         "<existing_owner_private_key>", //string
         "<array_of_serial_no>" //array of int (to trnasfer specific NFT from batch, provide selected NFT serial number. you can get the serial   number of NFT from hedera mirror nodes api)
     )
    

    J. Burn NFT Serial Number:

     burnNonFungibleToken(
         "<account_id>", // string 
         "<account_private_key>", // string
         "<token_id>", // string
         "<serial_number>" // array of int
     )
    
  4. Fungible Token:

    A. To create Fungible Token

     createFungibleToken(
         "<token_name>", // string
         "<token_symbol>", // string
         "<token_owner_account_id>", // string
         "<token_owner_account_key>", // string
         "<initial_supply>", // int
         "<decimals>", // int
     );
    

    B. To transfer fungible tokens to other hedera account

     transferFungibleToken(
         "<token_id>", // string
         "<token_sender_account_id>", // string
         "<token_sender_private_key>", // string
         "<token_reciver_account_id>", // string
         "<token_reciver_private_key>", // string
         "<token_quntity>" // int
     )
    

    C. To swap Fungible Token with Hbar

     swapFungibleToken(
         "<token_buyer_account_id>", // string
         "<token_buyer_private_key>", // string
         "<token_provider_account_id>", // string
         "<token_provider_private_key>", // string
         "<token_id>", // string
         "<quntity_of_token>", // int
         "<conversion_rate_with_Hbar>", // float
     )
     note: Here token buyer is who want to buy token with exchange of Hbar.
    

    D. To update Fungible Token Supply

     updateFungibleTokenSupply(
         "<token_id>", // string
         "<user_id>", // string
         "<user_key>", // string
         "<amount>", // int
     )
    
  5. Files:

    A. Create File

     createFile(
         "<account_id>", // string 
         "<account_private_key>", // string 
         "<content>", // string 
     );
    

    B. Read File

     getFileContent(
         "<account_id>", // string 
         "<account_private_key>", // string 
         "<content>", // string 
     );
    

    C. Update File

     updateFile(
         <account_id> // string,
         <account_private_key> //string,
         <file_id> // string,
         <file_key> // string,
         <content> // string,
     );
    

    D. Append File

     appendFile(
         <account_id> // string,
         <account_private_key> //string,
         <file_id> // string,
         <file_key> // string,
         <content> // string,
     )
    

    E. Delete File

     appendFile(
         <account_id> // string,
         <account_private_key> //string,
         <file_id> // string,
         <file_key> // string,
     )
    

Create new hedera account:

A. Create Hedera Acount using Private Key

createHederaAccount(<initial_balance_in_tinybars>)

B. Create Hedera Acount using 24 word Phrases

createAccountUsingPhrases(
    <initial_balance_in_tinybars> // int
    <array_of_24_phrases> // array of string
)

Transfer HBars

transferHBar(
    <sender_account_id>, // string
    <sender_private_key>, // string
    <reciver_account_id>, // string
    <amount> // float
)

Notes:

  1. We are not saving any private keys of users for security reasons.
  2. NFTs created through this package can be validated from hedera mirror node apis. (https://testnet.mirrornode.hedera.com/api/v1/tokens/{token_id}/nfts https://mainnet.mirrornode.hedera.com/api/v1/tokens/{token_id}/nfts)

Package Sidebar

Install

npm i hedera-services

Weekly Downloads

2

Version

1.0.40

License

ISC

Unpacked Size

46.7 kB

Total Files

25

Last publish

Collaborators

  • inara-consultancy-services