TransactionPack()

Summary

Route
Type
Example

/Transaction/Pack

POST

http://176.113.80.7:62000/api/Transaction/Pack

Description

Packs a transaction to a byte array

This is needed for sending a transaction

Request

Request Structure

{

// parameters common for all requests 
  
"MethodApi" : "string_value", // API method name to form and process a transaction

"PublicKey":"string_value", // Sender public key in Base58

"ReceiverPublicKey":"string_value", // Recipient public key in Base58

"Amount":"decimal", // Transaction amount

"Fee":"decimal", // Maximum fee approved by the user
  
"SmartContractSource":"String_value", //Source code of smart contract
  
"UserData":"string_value" // If needed extra information can be stored inside UserData

}

Request Parameters

MethodApi: string value - it’s vital to specify the API method to pack the transaction: "TransferToken", "TransferCS", "Delegation", "SmartDeploy", "SmartMethodExecute";

PublicKey: string_value - sender public key in base58

ReceiverPublicKey: string_value - recipient public key in base58

Amount: decimal - transaction amount as a decimal or integer number

Fee: decimal - maximum fee approved by the user as a decimal or integer number

UserData: string_value - data the user sent with the transaction including the data about deployment and initiation of a smart contract

Response

Response Structure

"dataResponse":{
    "transactionPackagedStr":"String_Value" // packed transaction as a string in base58
   },

Example Code

Python

import requests
import json
def Transaction_Pack():
    url =  'http://176.113.80.7:62000/api/Transaction/Pack'
    headers = {
        'Content-type': 'application/json'
        , 'Accept': 'application/json'
        , 'Content-Encoding': 'utf-8'
        }
    data = {
    "NetworkAlias":"Mainnet"
    , "MethodApi" : "TransferCS"
    , "PublicKey":"QTRbkssQSGLdKs94khX7i858YcBAhjg6wj48F7FTr8H"
    , "ReceiverPublicKey":"5118o9XpeykEnBvHVPNoZMicMgMWREq3Rxb77i3KGF4z"
    , "Amount":0.1
    , "Fee":1
    , "UserData":""     }  
    answer = requests.post(url, data=json.dumps(data), headers=headers)
    if answer.status_code == 200:
        response = answer.text
        return response
print(Transaction_Pack())

C++

#include <iostream>

#include <cpprest/http_client.h>
#include <cpprest/filestream.h>

using namespace utility;                    // Common utilities like string conversions
using namespace web;                        // Common features like URIs.
using namespace web::http;                  // Common HTTP functionality
using namespace web::http::client;          // HTTP client features
using namespace concurrency::streams;       // Asynchronous streams
using namespace web::json;

int main(int argc, char* argv[])
{
    web::json::value json_v;
    web::json::value json_return;
    json_v[L"authKey"] = web::json::value::string(L"");
    json_v[L"NetworkAlias"] = web::json::value::string(L"Mainnet");
    json_v[L"MethodApi"] = web::json::value::string(L"TransferCS");
    json_v[L"PublicKey"] = web::json::value::string(L"QTRbkssQSGLdKs94khX7i858YcBAhjg6wj48F7FTr8H");
    json_v[L"ReceiverPublicKey"] = web::json::value::string(L"5118o9XpeykEnBvHVPNoZMicMgMWREq3Rxb77i3KGF4z");
    json_v[L"Amount"] = web::json::value::number(0.1);
    json_v[L"Fee"] = web::json::value::number(1.0);
    json_v[L"UserData"] = web::json::value::string(L"");
    http_client client(U("http://176.113.80.7:62000"));

    client.request(web::http::methods::POST, U("/api/Transaction/Pack"), json_v)
        .then([](const web::http::http_response& response) {
        return response.extract_json();
    })
        .then([&json_return](const pplx::task<web::json::value>& task) {
        try {
            json_return = task.get();
        }
        catch (const web::http::http_exception& e) {
            std::cout << "error " << e.what() << std::endl;
        }
    })
        .wait();

    std::wcout << json_return.serialize() << std::endl;

    return 0;
}

C#

using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace Program.Getinfo
{
    public class PackTransaction
    {
        static readonly HttpClient client = new HttpClient();
        public class body
        {
            public string authKey { get; set; }
            public string networkAlias { get; set; }
            public string MethodApi { get; set; }
            public string PublicKey { get; set; }
            public string ReceiverPublicKey { get; set; }
            public double Amount { get; set; }
            public double Fee { get; set; }
            public string UserData { get; set; }
        }
        public static async Task Main()
        {
            try
            {
                var body = new body
                {
                    authKey = "87cbdd85-b2e0-4cb9-aebf-1fe87bf3afdd",
                    networkAlias = "Mainnet",
                    MethodApi = "TransferCS",
                    PublicKey = "QTRbkssQSGLdKs94khX7i858YcBAhjg6wj48F7FTr8H",
                    ReceiverPublicKey = "5118o9XpeykEnBvHVPNoZMicMgMWREq3Rxb77i3KGF4z",
                    Amount = 0.1,
                    Fee = 1,
                    UserData = ""
                };
                var httpContent = new StringContent(JsonConvert.SerializeObject(body),
                    Encoding.UTF8, "application/json");
                var response = await client.PostAsync("http://176.113.80.7:62000/api/Transaction/Pack",
                    httpContent);
                Console.WriteLine("RESPONSE=" +
                    await response.Content.ReadAsStringAsync());
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
    }
}

Last updated