sendTransaction()

Send a new transaction on the blockchain.

Requesting the content of a wallet should not be considered a transaction. This distinction arises because such a request is handled by a single node and does not affect the global state of the network. Transactions, in contrast, are actions that have an impact on the overall network state.

When we talk about "affecting the global state of the network," we mean that the requested action results in a change of state and requires the execution of an operation by all nodes in the network or a specific subset of nodes.

Transactions are typically used for various purposes, including modifying the contents of a wallet, executing smart contracts, or creating/modifying/destroying assets on the blockchains. Transactions are the primary mechanism for carrying out these diverse operations and involve several parameters to achieve the desired outcomes.

Method Signature

def sendTransaction(self, id, sender, to, timestamp, type, payload, nonce, signature, blockchain)

ID:

This represents the transaction hash, which is usually calculated as:

ID = "0x" + sha256(From + To + Payload + Timestamp + Blockchain + Nonce)

Where "From," "To," and "Payload" are in hexadecimal representation without the "0x" identifier, while the "ID" will contain the "0x" hexadecimal identifier.

From:

This field represents the wallet address of the entity initiating the transaction, without the "0x" hexadecimal identifier. Please note that the wallet address must be pre-registered on the chosen blockchain. Furthermore, the wallet must maintain an adequate balance of CIRX coins to cover the transaction fees associated with the particular transaction. These fees are essential for the seamless processing and execution of the requested transaction.

To:

This field represents the wallet address of the transaction recipient, without the "0x" hexadecimal identifier. If the particular transaction doesn't necessitate a recipient address, this field can be the same as the sender's address.

Timestamp:

Transaction timestamp in format YYYY:MM:DD-hh:mm:ss in UDT timezone.

Payload:

String in hexadecimal format without the "0x" hexadecimal identifier (base64 is also accepted).

Nonce:

Nonce value for the current transaction. It's crucial to obtain the current Nonce value from the sending wallet and incorporate it into the new transaction. For more information, please refer to the "getWalletNonce()" section.

Signature:

Signature of the transaction ID in hexadecimal format, without the "0x" identifier. The signature is obtained using Elliptic curve algorithm Secp256k1 (more cryptos will be available soon).

signature = circular.signMessage( ID, From_PrivateKey);

Public Key:

The public key of the "From" Wallet is included in the transaction to expedite the initial transaction pre-validation process. This eliminates the need to access wallet files for public key retrieval during this phase, thus enhancing the efficiency of the transaction.

Blockchain:

Blockchain Address where the transaction is sent, without the hexadecimal identifier.

Type:

Types of transactions:

  • C_TYPE_COIN: Transaction involving native coins (CIRX) without the use of Hyper Code (Smart Contracts).

  • C_TYPE_TOKEN: Transaction involving specified tokens without the use of Hyper Code.

  • C_TYPE_ASSET: Transaction involving a generic digital asset that is not represented by a token.

  • C_TYPE_CERTIFICATE: Transaction where the payload doesn't require processing and is a generic string.

  • C_TYPE_REGISTERWALLET: Transaction used to register a new wallet on a specified blockchain.

  • C_TYPE_HC_DEPLOYMENT: Transaction to deploy a new Hyper Code Program.

  • C_TYPE_HC_REQUEST: Transaction to call a specified endpoint of a Hyper Program.

  • C_TYPE_USERDEF: Unspecified type, defined by the user (not available yet).

Request

Parameters

Name
Type
Description

id

string or hexadecimal

Calculated TxID

from

string or hexadecimal

Wallet address

to

string or hexadecimal

Receiver's wallet address

timestamp

string

Date string in "YYYY:MM:DD-HH:mm:ss" format

payload

string or hexadecimal

String in hexadecimal format

nonce

string

Nonce value for the current transaction.

signature

string or hexadecimal

Signature of the transaction ID in hexadecimal

blockchain

string or hexadecimal

Blockchain address excluding the "0x" hexadecimal identifier

type

string

One of the types listed before

Example

from circular_protocol_api import CircularProtocolAPI
from circular_protocol_api import helper
from circular_protocol_api import nag_functions
import json

circular = CircularProtocolAPI()

blockchain = ""
sender = ""
to = ""
privateKey = ""

payload = {
    "Amount": "1",
    "Asset": "CIRX",
    "Action": "CP_SEND",
    "Memo": "Hello, World!"
}

timestamp = helper.getFormattedTimestamp()
blockchain = helper.hexFix(blockchain)
nonce = int(circular.getWalletNonce(blockchain, sender)["Response"]["Nonce"]) + 1
payload = helper.hexFix(json.dumps(payload).encode().hex())
privateKey = helper.hexFix(privateKey)
sender = helper.hexFix(sender)
to = helper.hexFix(to)
ID = str(blockchain + sender + to + payload + str(nonce) + timestamp)
hashID = helper.sha256(ID)
signature = helper.signMessage(hashID, privateKey)
transactionType = "C_TYPE_COIN"

data = {
    'ID': hashID,
    'From': sender,
    'To': to,
    'Timestamp': timestamp,
    'Type': transactionType,
    'Payload': payload,
    'Nonce': f"{nonce}",
    'Signature': signature,
    'Blockchain': blockchain,
    'Version': circular.getVersion()
}

result = helper.sendRequest(data, nag_functions._SEND_TRANSACTION, circular.getNAGURL())

Result

{
  "Result": 200,
  "Response": {
    "TxID": "138dd7a19685c71f281d8f5b9d0de15dc7ce7e9433e1715ec6e45e0fade74c82",
    "Timestamp": "2024:09:26-21:57:12"
  },
  "Node": "8a93c6b6f8d166097ddfeb3e5e3a2998b35e0b6f0bd2e31a8a130a11b6749279"
}

Last updated