Transaction signing

Let privateKey is 32 bytes EdDSA private key

Concatenate all bytes of transaction fields (for strings use utf8 encoding, for numbers such as nonce and timestamp - 8 bytes big-endian unsigned representation):

tags_bytes = concat(sort(tags))
data = concat(
    space
    key,
    bytes(nonce), // 8 bytes big-endian
    bytes(timestamp), // 8 bytes big-endian
    memo,
    tags_bytes, // concatenated array of tags
    value
)

Calculate hash = sha256(data)

Sign message signature = EdDSA.sign(privateKey, hash)

Create JSON object:

signedTransaction = {
    'space': space,
    'key': key,
    'nonce': nonce,
    'timestamp': timestamp,
    'tags': tags,
    'memo': memo,
    'value': value,
    'hash': encodeHex(tx_hash),
    'signature': encodeBase64(signature),
    'public_key': encodeBase64(public_key)
}

Create encoded transaction encodedTransaction=encodeBase64(signedTransaction)

Call API method /api/events/add?event={encodedTransaction}

If transaction is constructed and signed properly this endpoint will return 200 OK HTTP response. It doesn't mean transaction is immediately add to blockchain as processing is asynchronous. In order to check if transaction succeeded use provided in documentation API methods.

Here is the reference implementation of transaction signing in NodeJS

Last updated

Was this helpful?