In this chapter, you will understand how to create Smart Voucher Campaign via FsTK API and effectively distribute Smart Voucher.

Campaign is the vending machine of Smart Token/Voucher. You can set up the type of selling Smart Token/Voucher, activated selling period, selling amount and selling price in this campaign. This allows customers to automatically receive Smart Token/Voucher after purchase.

Table of Contents

  1. Prerequisite
  2. Encode the Transaction (creating smart voucher campaign)
  3. Decrypt the Ethereum Key JSON
  4. Sign the Ethereum Transaction
  5. Broadcast the Ethereum Transaction
  6. Confirm the Ethereum Transaction
  7. Confirm the Campaign
  8. Transfer SMart Token to the Campaign to obtain Smart Voucher
    1. Encode the Transaction (transferring smart token to voucher campaign)
  9. Check the progress of the Campaign
  10. Finalize the Campaign
    1. Prerequisite
    2. Encode the Transaction (finalizing campaign)

Prerequisite

  1. Please sign up an account on https://test.fstk.io or https://engine.fstk.io.

    Notice account data are NOT shared across both platform.

    • test.fstk.io is Tokeneden built on Kovan Testnet for agile software development, testing & demo.
    • engine.fstk.io is official Tokeneden built on Ethereum Mainnet.
  2. Please take a look at your asset balances of ETHFSTFIL and FST Service Gas.

    Please remember that assets on test.fstk.io belongs to Kovan Testnet; assets on engine.fstk.io belongs to Mainnet.

    • ETH is Ether, a small amount will be given to new accounts on test.fstk.io.
    • FST is Funder Smart Token, a fundamental Utility Token within FST Network and will be given to new accounts on test.fstk.io.
    • FIL is FundersToken Initialisation License as Token Issuance License, 1 FIL will be given to new accounts on test.fstk.io.
    • FST Service Gas is the FsTK module usage fee for Token Issuer, balance is shown at User Profile on the top right corner.
  3. Please prepare your API testing tools.
  4. Understand how to retrieve Access Web Token (JWT).

    Please refer to Quick start Chapter 1.

  5. Complete Quick start.
  6. Confirm sufficient Ether (ETH) for ETH gas fee.
  7. Confirm sufficient FST Service Gas for module service fee (at least 500 FST Service Gas), FST Service Gas will not be refunded after cancellation.
  8. Become Issuer (Token Issuer), please confirm token in get me.

Encode the Transaction (create smart voucher campaign)

In any of following API calls, please remember to assign access token to authorization in http request header.

Hereinafter let’s take FST Sport Shop as the example.

  • Using GraphQL (Insomnia recommended)
    • operations detail

      Variables:

      • id is the registered ID on FsTK system of selling Smart Token/Voucher, which can be retrieved from tokenin get me.
      • name is the name of Campaign, between 1 character to 20 characters.
      • description is the description of Campaign.
      • stages are Campaign stages. Currently Campaign only allows 1 stage.
        • name is the name of Stage, between 1 character to 20 characters.
        • startTime is the activated selling time of Stage, in Unix Timestamp in Milliseconds.
        • endTime is the ending time of Stage, in Unix Timestamp in Milliseconds.
        • priceMultiplier is the price multiplier (discount/markup) of Smart Token/Voucher at this Stage, e.g., a 10% off means 9/10; no discount means 1/1.
          • numerator is the numerator of price multiplier.
          • denominator is the denominator of price multiplier.
        • cap is the maximal selling amount of Smart Token/Voucher at this Stage in Decimaled Number. If selling Smart Voucher, this is the selling amount, otherwise selling Smart token, this requires a multiplier of 10^18. As Voucher is an integer with decimal = 0, 10^0 = 1.
        • isPrivate means whether this Stage is limited to customer identity (having special signature).
      • description is the description of Stage.
  • Using cURL
  • Response

    At the moment, API does not respond the value of consuming FST Service Gas. create a campaign will consume 500 FST Service Gas.

    In response’s transaction, object will be used to sign payload, submitToken is also required for broadcasting signed transaction.

    Please remember that response will vary after each call, please use the latest response for next steps.

    e.g. Response like

    means the transaction will fail. We suggest to skip the following steps and check related resources of Transaction are correct first. e.g. ETH balance, FST Service Gas balance, Token balance, Voucher balance, … etc..

Decrypt the Ethereum Key JSON

Please notice the difference between password and passphrase in FsTK system. password is required to sign in Tokeneden; passphrase is required to decrypt Ethereum key JSON and sign the transaction.

Word usage may be different in other libraries, i.e. passphrase means password.

To start with, use get me to fetch ethereumKey like the following:

This is current user’s Ethereum key JSON, which includes encrypted private key (by passphrase). This can be safely stored but remain private unless necessary.

Owning private key means owning the Ethereum Account. Please securely store Ethereum key JSON and passphrase.

WARNING: If the passphrase of Ethereum key JSON is lost, the private key is lost and FsTK does not have users’ Ethereum key JSON passphrase.

  • Using JavaScript (Node.js)

    Install eth-key-lib

    This is the module import of ES6. If your node.js does not support it, please refer to Webpack (target = "node") and the followings:

    Minimal webpack.config.js

    Minimal package.json

    Install command line (please let index.js be the program entry point).

    If working on windows, please refer to node-gyp on windows.

  • Using Java

    Please refer to Web3j. Notice that loadCredentials in WalletUtils method with this overload:

    In another way, as web3j only provides File import, please pay attention to OS storage or use in-memory-fs in Java.

    Please to refer to Web3j sample codes.

  • Using C#

    Please refer to Nethereum. Please refer to Nethereum sample codes.

    Please use Account.PrivateKey to fetch private key from Account.

Sign the Ethereum Transaction

  • Using JavaScript
  • Using Java

    Please refer to Web3j. Notice that signMessage in TransactionEncoder, and please use the overload below since the chainId must be included in the signature process.

    Please refer to Web3j sample codes.

  • Using C#

    Please refer to Nethereum. Please refer to SignTransaction in TransactionSigner, and please use the overload below since the chainId must be included in the signature process.

    Please refer to the section Nethereum.Web3.Accounts.AccountSignerTransactionManager.SignTransaction.

Broadcast the Ethereum Transaction

  • Using GraphQL (Insomnia recommended)

    Variables:

    data is the object from signing transaction with current user’s private key. In another word, signedTransaction is the hex string.

    submitToken is submitToken from Encode Ethereum Transaction.

  • Using cURL
  • Response

    transactionHash can be used to check whether transaction is confirmed in the next steps.

Confirm the Ethereum Transaction

  • Using GraphQL (Insomnia recommended)

    Variables:

    txHash is the transaction hash.

    Notice that transaction hash is unique on chain, but it may repeat when representing different transactions on different chain.

  • Using cURL
  • Response

    When remain in confirmations becomes 0, the transaction is confirmed.

    Notice that a confirmed transaction may not succeed. As on Blockchain, failed transaction is also a consensus. Please use Infura with ETH-JSON-RPC to fetch status (success/failure of transaction).

Confirm the Campaign

Please refer to token.vouchers in get me (More details in Quick start Chapter 2).

Transfer Smart Token to the Campaign to obtain Smart Voucher

Encode the Transaction (transferring smart token to voucher campaign)

In any of following API calls, please remember to assign access token to authorization in http request header.

Voucher Issuer will consume 0.15 FST Service Gas after customer purchases each Smart Voucher.

Hereinafter let’s take FST Sport Shop as the example.

  • Using GraphQL (Recommended Insomnia)
    • operations detail

    Variables:

    • id is the registered ID on FsTK system of Smart Token, which can be retrieved from getSmartTokenBalance.
    • to is the Campaign smart contract address of FSST_19FXSV.
    • value is the transferring amount. If the price of FSST_19FXSV is 2000 FSST, to purchase 1 FSST_19FXSV requires value = 2000000000000000000000.
  • Using cURL
  • Response

Check the progress of the Campaign

Information of Campaign, e.g. cap and sold, can be retrieved from getAllCampaignInfo API and shows the sales progress of current Campaign. (Please refer to API_Reference/Campaign/getAllCampaignInfo).

Finalize the Campaign

Prerequisite

There are 3 phases of Smart Voucher Campaign: pre sales, launch period and post sales. When finalizing the sales, there are different outcomes in each phase.

  1. Pre sales (now < startTime): Campaign is cancelled by the issuer and returns the unsold Smart Voucher.
  2. Launch Period (startTime < now < endTime): If Smart Voucher is sold out during Launch, issuer can claim back the Smart Token before endTime, otherwise issuer cannot cancel the Campaign or claim back remaining Smart Voucher and earned Smart Token.
  3. Post sales (endTime < now):issuer can claim back unsold Smart Voucher and earned Smart Token.

Encode the Transaction (finalizing campaign)

In any of following API calls, please remember to assign access token to authorization in http request header.

Hereinafter we take FST Sport Shop as the example.

  • Using GraphQL (Insomnia recommended)
    • operations detail

      Variables:

      • id is the ID of finalizing Campaign, which can be retrieved from getAllCampaignInfo.
  • Using cURL
  • Response

    Finalizing Campaign will not consume FST Service Gas.

    Is API succeeds, please follow 3 previous steps: 3. Decrypt the Ethereum Key JSON4. Sign the Ethereum Transaction5. Broadcast the Ethereum Transaction.

    e.g. Response like

    means the transaction will fail. We suggest to skip the following steps and check related resources of Transaction are correct first. e.g. ETH balance, FST Service Gas balance, Token balance, Voucher balance, … etc..