How to interact with the smart contract via API requests

For non-technical users, look out for our Android mobile application where you will be able to perform these actions without knowledge of using API requests. Release is being published the 24th of May.


Import required libraries


# The following examples have some ready added inputs to help understand the data types, feel free to change them to your own preferences once comfortable. Full API documentation on data types will be released soon.

# Pull the kujuaRelayChain library from GitHub

import sys
sys.path.append('')  # The path to the directory where you saved the library 'kujuaRelayChain'
import kujuaRelayChain.Client.functions as functions
import kujuaRelayChain.Client.inputs as inputs
import datetime
									

Let's first create an account to use


results = functions.generate_address(inputs.wallet.passphrase, '0x')
print(results)
									

Now, let's request some test dummy coins


results = functions.get_dummy_coins(inputs.node.node_url, inputs.wallet.wallet_address)
print(results)
									

Check your balance


results = functions.get_account_balance(inputs.node.node_url,
                                    	inputs.wallet.wallet_address)
print(results)
									

Lock an amount into the reserves vault


contract_generate = {
    "owner_address": "0xa0057d7d2b7ad8cb3ed634be4e8be079dac38ace0c8c5413efcfb7d922567b74",  # The owner to whom these assets were issued
    "currency": "KES",
    "lock_ratio": 3,
}

contract_args = {
    "action": "lock_reserves",
    "notify_address": "0xa0057d7d2b7ad8cb3ed634be4e8be079dac38ace0c8c5413efcfb7d922567b74",
    "resend_to_contract": False,  # Used by the contract to resend to itself
    "proof_of_action_values": "",  # Used by the contract to resend to itself as proof of a transaction to allow changing the key 'resend_to_contract' to True
    "contract": contract_generate,
}
									

Generate a contract using your locked reserves for another party (or in this example, for yourself)


contract_generate = {
    "owner_address": "0xa0057d7d2b7ad8cb3ed634be4e8be079dac38ace0c8c5413efcfb7d922567b74",  # The owner to whom these assets were issued
    "asset": "Kenyan Shillings",
    "currency": "KES",
    "value": 20,
    "utc_time": int(
        datetime.datetime.utcnow().strftime("%Y%m%d%H%M%S%f")
    ),  # In milliseconds, used to get the entry price from an exchange so that we know whether the locked value is still above capacity to handle exchanging the asset to liquid cash
    "receipt_date_id": 19990101,  # Used for expiration date calculations
    "claimed_univ_sequential_hashes": [
        "c0a1b26999f2f99bf98a919d7d9baf13c3482821f0dfed3ae461f137625ffeec",  # The claimed universal sequential hashes to cover the transaction_value or those to be sold back into the reserves
    ]
}

contract_args = {
    "action": "generate_contract",
    "notify_address": "0xa0057d7d2b7ad8cb3ed634be4e8be079dac38ace0c8c5413efcfb7d922567b74",
    "resend_to_contract": False,  # Used by the contract to resend to itself
    "proof_of_action_values": "",  # Used by the contract to resend to itself as proof of a transaction to allow changing the key 'resend_to_contract' to True
    "contract": contract_generate,
}
									

Transact your generated contract balance from your account to another


contract_generate = {
    "owner_address": "0x0140e817d6da8d44f44676d1fb6aef5db17e8114a2fa5794dd15490524c02ca3",  # The owner to whom these assets will be issued / split with. The recipient in this case.
    "currency": "KES",
    "transaction_value": 5,  # The value that the holder of this issued contract is sending to someone else
    "claimed_univ_sequential_hashes": [
        "1a045401e21c77a35363e1783cb15a89e20a16397b01e15942afa5376d2b8cd4",  # The claimed universal sequential hashes to cover the transaction_value or those to be sold back into the reserves
    ]
}

contract_args = {
    "action": "transact_api",
    "notify_address": "0x0140e817d6da8d44f44676d1fb6aef5db17e8114a2fa5794dd15490524c02ca3",
    "resend_to_contract": False,  # Used by the contract to resend to itself
    "proof_of_action_values": "",  # Used by the contract to resend to itself as proof of a transaction to allow changing the key 'resend_to_contract' to True
    "contract": contract_generate,
}
									

Place a withdrawal order for your locked reserves


# This order will be executed at Close of Day
contract_args = {
    "action": "withdrawal_order",
    "notify_address": "0xa0057d7d2b7ad8cb3ed634be4e8be079dac38ace0c8c5413efcfb7d922567b74",
    "cancel_existing": True,  # Used to cancel an existing order only OR Cancel an existing order to place a new order in the same day
    "resend_to_contract": False,  # Used by the contract to resend to itself
    "proof_of_action_values": "",  # Used by the contract to resend to itself as proof of a transaction to allow changing the key 'resend_to_contract' to True
    "withdraw_reserves_amount": 0.0134,
    "withdraw_process_date_id": "20230125",
}
									

Sell the contract back into your issuer's reserves


contract_generate = {
    "amount": 30,
    "claimed_univ_sequential_hashes": [
        "e5551281219adcbfcc60977a484ca701d66ddd596140feb672c33e87c38c5958",  # The claimed universal sequential hashes to cover the transaction_value or those to be sold back into the reserves
    ]
}

contract_args = {
    "action": "sell_contract",
    "notify_address": "0x59a4e48cc661b10ea598f20088df4572f12d6a8caa08f3136d7af01efdb6497a",
    "resend_to_contract": False,  # Used by the contract to resend to itself
    "proof_of_action_values": "",  # Used by the contract to resend to itself as proof of a transaction to allow changing the key 'resend_to_contract' to True
    "contract": contract_generate,
}
									

Pass each of the above requests through the broadcast function. That's it! You now know how to perform all the functions of JuaPay.


fees = functions.calculate_fees(
    0.0001, inputs.node.node_url, inputs.dummy.recipient_address
)
print(fees)

# Broadcast the transaction packet
broadcast = functions.broadcast(
    inputs.wallet.wallet_address,
    inputs.wallet.private_key_encrypted,
    inputs.wallet.passphrase,
    0.0001,  # Contract will use amount_lock as amount, this is for the blockchain, we also dont want to pay a large fee on the blockchain as the contract will charge us the normal fee separately. Use this when locking reserves though.
    fees["content"]["full_fee"],
    inputs.node.node_url,
    str(),
    inputs.dummy.recipient_address,
    str(),
    0,
    0,
    contract_args['notify_address'],
    str(),
    contract_args,
    {},
    True,
    inputs.node.gt_node_url,
    True,
    {},
)
print(broadcast)
									

We use the on chain method by importing kujuaOnChain. Meaning the functions run directly on the node and return results. Off chain will be available with the full Github release. You can find the code for kujuaOnChain on GitHub