Sending Transactions to the SWT Blockchain
Introduction
For illustration purposes, we’ll send 0.1 SWT on the MainNet network from wallet A to wallet B.
An algorithm ED25519 is used to generate a transaction signature. For security reasons, the signing process occurs on the client-side to avoid transmitting the private key.
There are various libraries for different programming languages that allow generating a key pair from the private and public keys, validating the digital signature, etc.
We will illustrate how to send a transaction to the blockchain with Python 3.
We will use libraries “ed25519” and “base58check” to work with keys. The latter is used to display the keys in a human-readable base58 format. You can install the libraries with pip (or pip3):
For JS : tweetnacl and bs58 can be used.
You should do the following actions to send a transaction (transfer SWT or call a smart contract method) in the network:
Use the API to generate a correct set of transaction bytes from transaction data (transaction/pack)
From transactions bytes received from the Rest API on step 1, generate a digital signature with the private key
Dependencies Python
These packages need to be installed
pip install base58check
pip install ed25519
Key generation
You should execute the following code to generate the keys:
You can execute this code by copying it line by line to the Python IDLE interpreter. As a result, you will get public and private keys in the form they are transferred to the web-services, like explorer.swttoken.com.
Creating/Pack a transaction
For illustration purposes, we’ll send 0.1 SWT on the MainNet network from wallet A to wallet B. We will use the “requests” library to send the REST API requests and the “JSON” library to work with the data.
The code above allows you to retrieve from REST a properly generated set of transaction bytes and send it again using “Execute()” function
Signing a Transaction
For illustration purposes, we’ll sign a transaction with the private key by uploading it from the base58 format line, and add the resulting signature to the “Execute()”. Below is the full code with comments.
Last updated