Signature and Broadcast Steps

Introduction

The Vision network has offical API calls to allow users to interact with the blockchain. These API calls can be found in the API reference page, which lists API calls from Full Node, Solidity Node, and VisionWeb. While some of the API calls serve as stand-alone requests to get individual pieces of information, there are also many API calls which modify the user VS wallet, resulting in a need to sign and broadcast the transaction. This guide walks the user through a VS Balance staking example to show the API signature and broadcast process flow.

Stake Balance Example

One of the most commonly used APIs is the /wallet/freezebalance call. This API call stakes your VS balance within a user-specified wallet address, and provides either photon OR entropy to the wallet owner. This API call takes in the four input parameters of owner_address, frozen_balance, frozen_duration, and resource:

  • owner_address is the VS wallet's address in string format.
  • frozen_balance is the amount of VS staked in denominations of VDT, in integer format.
  • frozen_duration is the duration in days to be staked, in integer format.
  • resource is the type of resource staking for. This can be either ENTROPY or PHOTON, in string format.
  1. Make a Transaction: stake balance by making the API call to get the JSON data:

Below is the sample JSON output. It lists the various attributes associated with the stake balance transaction. This JSON output will be used to sign the transaction.

{  
   "transaction":{  
      "txID": "1ba56d6ee2e7a44dad148c14eeffccbdb5b6f81dad9feb54bfcda3359b5c98d0",
      "raw_data": {
        "contract": [
          {
            "parameter": {
              "value": {
                "resource": "ENTROPY",
                "frozen_duration": 3,
                "frozen_balance": 1000000,
                "owner_address": "463f06a5ec6b90fa1ee9945793fab5c0aea1e16639"
              },
              "type_url": "type.googleapis.com/protocol.FreezeBalanceContract"
            },
            "type": "FreezeBalanceContract"
          }
        ],
        "ref_block_bytes": "13bf",
        "ref_block_hash": "77b9a3d77a07f2b2",
        "expiration": 1634010162000,
        "timestamp": 1634010102673
        }
   },
   "privateKey":""
}
  1. Sign the Transaction: The /wallet/gettransactionsign API call takes in two parameters. One is the transaction parameters, which takes in the JSON output from the previous step. The other is the privateKey parameter, which requires the private key associated with the staked VS address to sign the transaction.

Below is the sample JSON output, with the signature ID:

{  
   "signature": [
      "0c230a203ac3b66ce0aaff6d63399848ab1404068039212280fafa319929de6bf30c6ff1cdc15509a22b26713122f55a0332699ea5d21e2dbf90034c827cc20601"
    ],
    "txID": "1ba56d6ee2e7a44dad148c14eeffccbdb5b6f81dad9feb54bfcda3359b5c98d0",
    "raw_data": {
      "contract": [
        {
          "parameter": {
          "value": {
            "resource": "ENTROPY",
            "frozen_duration": 3,
            "frozen_balance": 1000000,
            "owner_address": "463f06a5ec6b90fa1ee9945793fab5c0aea1e16639"
          },
          "type_url": "type.googleapis.com/protocol.FreezeBalanceContract"
        },
        "type": "FreezeBalanceContract"
        }
      ],
      "ref_block_bytes": "13bf",
      "ref_block_hash": "77b9a3d77a07f2b2",
      "expiration": 1634010162000,
      "timestamp": 1634010102673
    },
}
  1. Broadcast Transaction: The /wallet/broadcasttransaction API call takes in one parameter, which is the JSON output data from signing the transaction.

Below is the sample JSON Output, confirming successful transaction broadcast.

{"result": true}