Transactions

How Olyn helps you leverage web3 transactions effortlessly

Introduction

Transactions are the mechanism to communicate with a smart contract, asset, or feature around web3. In the same way, to communicate with APIs you can either use XML, JSON, etc ... transactions are the way to reach the blockchain successfully when you're trying to perform a write operation (creating or updating a resource).
Transactions have different parts inside.

  • Destination: Points to the smart contract to interact with.
  • Information about the parties involved: If there's any other party besides the Smart-Contract itself a level of data is needed.
  • Data: The actual payload sent to the smart contract.
  • Authorization: A set of signatures to properly operate in the blockchain.

NOTE: For services or tools using a web3 framework but located outside a blockchain the only fields requires are Data, often reffed as a Message, and Authorization.

Olyn API handles the three first parts of the Transaction, in order for the developer to focus just on retrieving the authorization and streamlining and reducing their system flow.

How to handle Transactions

We provide a set of tools for developers to handle just the Authorization part.
When accessing a set of resources from either assets/ or the sub-resource assets/web3/ in the response body, there will be the following fields.

{
    "data": {
        "token": [
            {
                "transactionId": "fd432fc6-8280-4ada-95b9-fe012f557ba0",
                "estimatedTokenCost": 0.0011136,
                "serializedTransaction": "020002046a267f8aa87c0a8a83e090b1d5c1cab02171595a4cf6c5433a031ab188e2dad5845acf390be93881af310d3368137e171364d63ec7730b71e7bc72ed52e7bc4200000000000000000000000000000000000000000000000000000000000000010bb31cf411bb7ea5bb4f594f14b747fbbef8b323dbed87be5e4dd888b56b69418cf5b6b5fa758c9851378eb64d5e215d7ece9dfa5bad4244372d736318aa008f010304000001027f7a0000006c6f63616c686f73743a353030312f76315f315f302f6173736574732f63366539373834312d616265342d343863342d613866612d6438656462306362633737642f776562332f736f6c616e612f397566385438374774594c51694b486458767047767772624d6270644d4167596f396b50354459573950623700",
                "transactionStatus": "to_sign",
                "chain": "solana",
                "owner": "89NGK1ZaE1KyVeaLwajLcreSNJjAkCDo4gwGZrHuWP48"
            }
        ]
    }
}

Here we can appreciate the following information related to the blockchain.

  • transactionId, internal id for this transaction within Olyn.
  • estimatedTokenCost, The dost of the transaction in the native token from the chain
  • serializedTransaction, Transaction to be authorized.
  • transactionStatus, The current status of the transaction.
  • chain, The chain destination for the transaction
  • owner, The address that will have the blockchain resource (token, fallback rules, etc..) associated with it.

Signing transactions

In order to sign the transaction, you need to:

  1. take the value from token -> serializedTransaction which will be formatted to Hex
  2. Serialize back the transaction, (this part is just the data part from the transaction, also called Message).
  3. Ask the owner to sign it.
  4. Encode the Signature into Hex
  5. Attach it to the request to process the transaction.

See this mocked example in Pseudocode or Python.

message_to_sign = "020002046a267f8aa87c0a8a83e090b1d5c1cab02171595a4cf6c5433a031ab188e2dad5dff3902719f414d80278594e9db81856c513d0984cc299acd9ef052cc9d0f57b0000000000000000000000000000000000000000000000000000000000000001a534983577d8a701f7c9efb1cdbc21c797ce0227bab6024158f80b1b7aecbb9e1affb1ddcbf40478fe89bf79669de61c3c5b23e3a7defddfbafdcbfa62e87cf7010304000001028701f682a07ebae6954a7a0000006c6f63616c686f73743a353030312f76315f315f302f6173736574732f62306131323935322d353764612d346230612d623663612d3635653232363533636633342f776562332f736f6c616e612f4735444b725271704a4e445465526a33654e72767365556f566b687855386d6f6a76636e48456a544369446700"
seed = b'<Seed_as_bytes>'
owner = Wallet.generate_from_seed(seed)
pub_key = owner.public_key
print("PubKey: ", "\n",  pub_key)

signature = owner.sign_message(to_bytes(message_to_sign))
print("Signature: ", "\n", signature.to_hex())
message_to_sign = "020002046a267f8aa87c0a8a83e090b1d5c1cab02171595a4cf6c5433a031ab188e2dad5dff3902719f414d80278594e9db81856c513d0984cc299acd9ef052cc9d0f57b0000000000000000000000000000000000000000000000000000000000000001a534983577d8a701f7c9efb1cdbc21c797ce0227bab6024158f80b1b7aecbb9e1affb1ddcbf40478fe89bf79669de61c3c5b23e3a7defddfbafdcbfa62e87cf7010304000001028701f682a07ebae6954a7a0000006c6f63616c686f73743a353030312f76315f315f302f6173736574732f62306131323935322d353764612d346230612d623663612d3635653232363533636633342f776562332f736f6c616e612f4735444b725271704a4e445465526a33654e72767365556f566b687855386d6f6a76636e48456a544369446700"
seed = b'<Seed_as_bytes>'
owner = Keypair().from_secret_key(seed)
pub_key = owner.public_key
print("PubKey: ", "\n",  pub_key)

signature = owner.sign(bytes.fromhex(message_to_sign))
print("Signature: ", "\n", signature.__bytes__().hex())

Flows that Olyn offers to handle transactions

Transaction being handled by the developer

5031

The developer handles the transaction to sign. NOTE: The developer can sign the transaction by itself if defined before.

Transaction being forwarded to the owner

5401

The transaction is forwarded to the owner via redirect URL, and once completed is redirected back to the URL defined by the developer.

Transaction being handled entirely by Olyn

6471

Olyn handles the entire transaction and pays for it, and removes the cost to the developer's account.