• Brendan Lee

Setting up the Tokenized Smart Contract Agent (3/5)

Updated: Feb 12, 2020

As we discussed in our previous posts, the Tokenized Smart Contract Agent is an autonomous process that responds to commands written to its address on the ledger.

Every request that pays the correct fees gets a response, and any request that is a correctly formatted request using the Tokenized protocol which asks the contract to do something which is within its defined ruleset is followed by a response action carrying out that request from the agent. If someone tries to do something outside the rules, the agent responds with a rejection action. All actions are encapsulated within Bitcoin transactions, giving attackers almost no surface from which to attack a Tokenized smart contract.

The agent is currently still in beta so there isn’t yet a simple binary to download so you will need to download and install it manually. These instructions are valid in both Mac and Linux environments.

Downloading the smart contract code

Once you have installed go, downloading the code and binaries is as simple as typing:

$ go get github.com/tokenized/smart-contract/cmd/...

from a bash prompt. The first time this can take a while (almost half an hour for me)

but once you’ve downloaded the full dependency set it tends to go a lot faster.

If you are keen, you can download the source code and build the binaries yourself,

and there are detailed instructions on how to do this at the Tokenized Github repository:


Smart Contract configuration

Once you have the smart contract installed you must setup the agent’s configuration file.

I am going to set this smart contract up to manage shares in my Coinstorage business which sells the SAFEWORDS key backup kit.

I started by copying the example config file provided with the source into the ~/.contract folder using the following command:

$ cp conf/dev.env.example ~/.contract/coinstorage.env

I then opened the file in ‘nano’ to make the required changes:

$ nano ~/.contract/coinstorage.env

This is what my .env file looks like now:

Starting the agent

Once you have created the export file with the correct options for your configuration, starting the smart contract agent is as simple as executing the following command from your user directory:

$ source .contract/coinstorage.env && smartcontractd


You are now running the Tokenized Smart Contract Agent.


Setting up the client tool

The tokenized package comes with a simple client tool that allows you to build and send Tokenized packets from within your CLI.

To configure this, start by creating a folder for your config file:

$ mkdir ~/.client

Now copy the example file across into your new directory:

$ cp ~/go/src/github.com/tokenized/src/smart-contract/conf/cli.dev.env.example ~/.client/cli.dev.env

Now use nano to edit the file:

$ nano ~/.client/cli.dev.env

I used the following settings:

NOTE: When inputting the CLIENT_CONTRACT_ADDRESS make sure to use the COMPRESSED ADDRESS format as the Smart Contract will not see any transactions sent to the address that corresponds to the uncompressed address.

With this file, we can now execute commands via the smart contract tool to build and send on-chain actions to interact with the agent.

You can set the CLIENT_START_HASH to a value from a recent block in order to reduce the time it will take to synchronise. For this project, we will start from block 610,000 which was mined on the 23rd of November 2019, however if you are starting today it would be very easy to set this to block 620538 and only look at history post Genesis (Woohoo!!).

Funding and synchronising the Client

To prepare for the creation of your smart contract, your client must have funds. Simply send a small amount (say 10c) to the address that corresponds to the WIF in your client definition file. Once you have sent the funds, execute the following from the command line in your user directory:

$ source ~/.client/cli.dev.env && smartcontract sync

It took about 5 minutes to synchronise with the funds I sent.

Next week we will look at how to fund our administrative address and communicate with the smart contract to create a Smart Contract.


Blog 1

Blog 2

Blog 3- You're reading it.

Blog 4

Blog 5

About the Author

Mr. Lee's career to date has been focused on increasingly senior roles within industrial design, automation, and control, focusing on software design and implementation. Most recently, Mr. Lee was the Bitcoin Engineering Lead for the Tokenized project team who developed the Tokenized protocol. The Tokenized protocol is a comprehensive, regulation-friendly solution for businesses to create tokens for real-world assets on the BSV blockchain.

Subscribe to our FREE weekly newsletter 

to follow our journey into building a business at the intersection of community & technology.

Subscribe to our weekly newsletter to follow our journey into building a business at the intersection of community & technology. 

©2019 by Faiabrand Pte Ltd