Developers
  • SWT PROTOCOL
    • Introduction
    • Accounts
    • Transactions
    • Fees
    • Smart Contracts
  • GETTING STARTED
    • Network Node
      • Introduction
      • STEP 1:RENTING A LINUX VPS
      • STEP 2:INSTALLATION OF PUTTY
      • STEP 3:INSTALLATION OF FILEZILLA
      • STEP 4:VPS CONNECTION AND LINUX CONFIGURATION WITH PUTTY (SSH)
      • STEP 5:HOW TO SECURE YOUR VPS
      • STEP 6:USING TMUX THROUGH PUTTY
      • STEP 7:UPLOAD OF THE SWT SOFTWARE WITH FILEZILLA
      • STEP 8:EXTRACT THE SWT SOFTWARE FOLDER
      • STEP 9:RUNNING THE SWT NODE THROUGH TMUX
      • STEP 10:RUNNING THE MONITORING TOOLS
  • API REFERENCE
    • Apache Thrift API
      • Transactions
      • Blocks
      • Smart contract
      • Tokens
      • Wallets
      • Sync info
      • Data structures
    • REST API
      • GetBlocks()
      • GetNodeInfo()
      • GetBalance()
      • GetWalletInfo()
      • GetTokenBalance()
      • GetTransactionsByWallet()
      • GetTransactionInfo()
      • GetEstimatedFee()
      • GetContractByAddress()
      • GetContractFromTransaction()
      • GetContractMethods()
      • ContractValidation()
      • ContractCall()
      • TransactionPack()
      • TransactionExec()
  • SMART CONTRACTS
    • Creating "Hello-world" Smart Contract
    • Smart Contract Methods
    • Smart Contract Standarts
      • Token Smart Contract
      • Escrow Smart Contract
      • Stable coin Token
  • HOW TO REST API
    • Introduction
    • Retrieve a balance from the blockchain
    • Request a specific transaction from the blockchain
    • Sending Transactions to the SWT Blockchain
    • Validating and deploying a Smart Contract with REST API
Powered by GitBook
On this page
  • Summary
  • Description
  • Request
  • Response
  • Example Code
  1. API REFERENCE
  2. REST API

TransactionExec()

Summary

Route
Type
Example

/Transaction/Execute

POST

http://176.113.80.7:62000/api/Transaction/Execute

Description

Sends a transaction to the network.

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

 "Method":"string_value" // Invoked smart contract method
  
 "SmartContractSource":"String_value", //Source code of smart contract

 "Args":"string_value" // Arguments for the execution of a smart contract method

 "UserData":"string_value" // If needed extra information can be stored inside UserData

 "TransactionSignature":"string_value" // Signature in base58 retrieved with TransactionPack()

}

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

TransactionSignature: string_value - transaction signature in base58

Response

Response Structure

{
   "transactionInnerId":"Double_Value", // Inner Transaction value 
   },
   "transactionId":"String_Value", // Transaction ID in the blockchain String_Value
   "success":"Bool", // Bool if Transaction was a succes
   "message":"String_Value" // Message why the Transaction was failed
}

Example Code

Python

import requests
import ed25519
import json
import base58
def Transaction_Exec():
    package = bytes(Transaction_Pack(), 'utf-8') #Function TransactionPack called
    signing_key = ed25519.SigningKey(base58.b58decode("31LtZKYoMPvnajWXG2GBJxgqzmUdZjEnvw7w92aMVvFjD4xY92XFuup7dZ3PsNqkMrcKLg9V2HqTFRmotJ7oajnc"))
    sign = signing_key.sign(base58.b58decode(package))
    sign = str(base58.b58encode(sign)).strip('b').strip("'")
    url =  'http://176.113.80.7:62000/api/Transaction/Execute'
    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":""
    , "TransactionSignature":sign     }  
    answer = requests.post(url, data=json.dumps(data), headers=headers)
    if answer.status_code == 200:
        response = answer.text
        return response
print(Transaction_Exec())
PreviousTransactionPack()NextCreating "Hello-world" Smart Contract

Last updated 1 year ago