Deploy Smart Contract

The first step is to originate (deploy) the ownership Smart Contract with the admin test account that comes preconfigured with completium CLI.

Before anything, check the admin account balance. Open a new Terminal tab and enter the command below:

completium-cli show account

If the balance is below 3 tezies, then follow these instructions to import a new account (or transfer some tezies to the admin account).

Create smart contract file#

Create a file named ownership.arl by right clicking in the left-hand panel:

Docusaurus with Keytar

Copy contract code#

Copy-paste in ownership.arl the source code below and save the file (with ctrl/cmd + s).

(Click 'copy' in the upper-right-hand corner of the area below)

archetype asset_ownership
variable assetid : bytes =
variable owner : address = @tz1MZrh8CvYkp7BfLQMcm6mg5FvL5HRZfACw
variable bestbidder : address = owner
variable bestbid : tez = 0tz
variable endofbid : date = now
states =
| Owned initial
| ForSale
transition upforsale (price : tez) {
called by owner
from Owned to ForSale
with effect {
bestbid := price;
endofbid := now + 5m;
entry bid() {
require {
r1 otherwise "Asset Not For Sale": state = ForSale;
r2: now < endofbid;
r3: caller <> bestbidder;
r4: transferred > bestbid;
effect {
if balance <> transferred then
transfer bestbid to bestbidder;
bestbidder := caller;
bestbid := transferred;
endofbid += 2m;
transition claim () {
require { r5 otherwise "Bid Period Is Still On": now > endofbid }
from ForSale to Owned
with effect {
if balance > 0tz then
transfer balance to owner;
owner := bestbidder;

Originate contract#

Enter this command in the Terminal:

completium-cli deploy ownership.arl

It displays the main origination parameters and asks for confirmation. Enter Y and press enter.

The output should look like:

$ gitpod /workspace/completium-dapp-first $ completium-cli deploy ownership.arl
? Confirm contract ownership.arl origination by 'admin' with 0 ꜩ on edo? Yes
Waiting for confirmation of origination for KT1BAVw4WhU7BAs2jiakDv4VrR9CNzQK32rd ...
Origination completed for KT1BAVw4WhU7BAs2jiakDv4VrR9CNzQK32rd named ownership.arl.

Click on the generated link to display the contract in Better Call Dev indexer (it may take up to a dozen of seconds for BCD to synchronize with the blockchain). It shows the origination cost of 0.39ꜩ.

Contract API#


This section is for information only, no action is required.

This section presents the contract API.


The contract stores the asset id and the owner address:

NameTypeDescriptionInitial Value
assetIdbytesHash code of the asset.0x68746e... (see below)
owneraddressAddress of the current asset owner.tz1M...ACw (see below)

It stores 4 extra variables used to implement the transfer of ownership process:

NameTypeDescriptionInitial Value
bestbidderaddressAddress of the best bidder; it is equal to the owner address when asset is not for sale.owner
bestbidtezBest bid amount.0tz
endofbiddateDate of the end of (date of origination)
_stateintValue is either 0 (not for sale) or 1 (for sale).0 (not for sale)


The ownership contract provides three entrypoints:

upforsaleminimum selling priceCalled by current owner to open bid process. Resulting contract state is ForSale.
bidCalled by anyone. It requires:
  • the asset to be up for sale
  • the bid period is not over
  • the transferred amount is above the current best bid amount
If these conditions are met, it transfers back the previous best bid amount to the previous best bidder, and updates the bestbidder and bestbid variables with new values; endofbid is incremented by 2 minutes.
claimCalled by anyone. It requires:
  • the asset to be up for sale
  • the bid period to be over
If these condidions are met, it transfers the best bid value to the previous owner, and sets the owner variable to the best bidder address. Contract state is set back to "not for sale".