Sending Transactions to the Credits Blockchain

Introduction

For illustration purposes, we’ll send 0.1 CS on the TestNet 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 CS or call a smart contract method) in the network:

  1. Use the API to generate a correct set of transaction bytes from transaction data (transaction/pack)
  2. 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

  1. pip install base58check
  2. pip install ed25519

Key generation

You should execute the following code to generate the keys:

Python
Copy

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 monitor.credits.com and wallet.credits.com

A simpler way to generate the keys is to use the service https://wallet.credits.com where by clicking on “New Wallet”, it will generate public and private keys for you

Creating/Pack a transaction

The wallet must contain some CS before any transactions can be performed on it. It is best practice to check the wallet balance prior to initiating a transaction using the GetTransactionInfoREST request described above.

For illustration purposes, we’ll send 0.1 CS on the TestNet 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.

Python
Copy

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.

Python
Copy

The goal of this example is to illustrate REST capabilities to connect with the Credits blockchain. By using the documentation from Developer’s Portal it’s possible to perform various functions ranging from retrieving the information about transactions to the deploying or executing smart contracts. For these purposes, the same mechanisms are used as described above.

Type to search, ESC to discard
Type to search, ESC to discard
Type to search, ESC to discard