Deploy Smart Contract
The first step is to originate (deploy) the ownership Smart Contract with completium CLI.
Before anything, create a new account and provide it with some ghostnet tez:
- Generate a new account with the following
completium-cli
command in a VS code Terminal tab:
completium-cli generate account as first-dapp-account
where first-dapp-account
is the logical name of the account; you may give it another name.
Copy the
tz1...
address generated by command above, and go to ghostnet faucet; provide the account with ghostnet by setting thetz1...
address in the "Or fund any address" section.Set default endpoint with:
completium-cli set endpoint https://ghostnet.ecadinfra.com
- Set default account to
first-dapp-account
:
completium-cli set account first-dapp-account
- Check that balance is strictly positive with:
completium-cli show account
Smart contract code
note
This section is for information only, no action is required.
The contract is written in Archetype language. The source code is available in the contract
folder.
archetype asset_ownership(owner : address)
variable assetid : bytes =
0x68746ecbcd72793aefda48f1b67a3190fc380a7633055d2336fb90cd990582a2
variable bestbidder : address = owner
variable bestbid : tez = 0tz
variable endofbid : option<date> = none
states =
| Owned initial
| ForSale
transition upforsale (price : tez) {
called by owner
from Owned to ForSale
with effect {
bestbid := price;
endofbid := some((now + 5m));
}
}
entry bid() {
state is ForSale otherwise "Asset Not For Sale"
require {
r1: endofbid ? now < the : false otherwise "Bid Period Is Over";
r2: caller <> bestbidder otherwise "Called By Best Bidder";
r3: transferred > bestbid otherwise "Invalid Transferred Amount";
}
effect {
if balance <> transferred then
transfer bestbid to bestbidder;
bestbidder := caller;
bestbid := transferred;
endofbid := some((now + 2m));
}
}
transition claim () {
require { r5: endofbid ? now > the : false otherwise "Bid Period Is Still On" }
from ForSale to Owned
with effect {
if balance > 0tz then
transfer balance to owner;
owner := bestbidder;
}
}
Originate contract
From Archetype
Enter this command in the Terminal:
completium-cli deploy ./contract/ownership.arl --parameters '{ "owner" : "tz1h4CiqWxNe4UxSpkwXy617RM6DaK6NU76P" }'
warning
Replace address tz1h4CiqWxNe4UxSpkwXy617RM6DaK6NU76P
by the first-dapp-account
account you generated
(run completium-cli show account
to display the address - Public Key hash).
It displays the main origination parameters and asks for confirmation. Enter Y
and press enter.
The output should look like:
$ completium-cli deploy ./contract/ownership.arl --parameters '{ "owner" : "tz1h4CiqWxNe4UxSpkwXy617RM6DaK6NU76P" }' --force
Originate settings:
network : ghostnet
contract : ownership
as : first-dapp-account
send : 0 ꜩ
storage : (Pair "tz1h4CiqWxNe4UxSpkwXy617RM6DaK6NU76P" (Pair 0x68746ecbcd72793aefda48f1b67a3190fc380a7633055d2336fb90cd990582a2 (Pair "tz1h4CiqWxNe4UxSpkwXy617RM6DaK6NU76P" (Pair 0 (Pair 1635064614 0)))))
total cost : 0.42918 ꜩ
Waiting for confirmation of origination for KT1PPMXvCQh2g3b4YP4ovha5ZwpbKhh5xNh5 ...
Origination completed for KT1PPMXvCQh2g3b4YP4ovha5ZwpbKhh5xNh5 named ownership.
https://better-call.dev/ghostnet/KT1PPMXvCQh2g3b4YP4ovha5ZwpbKhh5xNh5
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ꜩ.
From Michelson
In order to originate from the Michelson version (available in contract
folder), enter the following command :
completium-cli originate ./contract/ownership.tz --init '(Pair "tz1h4CiqWxNe4UxSpkwXy617RM6DaK6NU76P" (Pair 0x68746ecbcd72793aefda48f1b67a3190fc380a7633055d2336fb90cd990582a2 (Pair "tz1h4CiqWxNe4UxSpkwXy617RM6DaK6NU76P" (Pair 0 (Pair 1624952132 0)))))'
warning
Replace twice address tz1h4CiqWxNe4UxSpkwXy617RM6DaK6NU76P
by the first-dapp-account
account you generated
(run completium-cli show account
to display the address - Public Key hash).
Contract API
note
This section is for information only, no action is required.
This section presents the contract API.
Storage
The contract stores the asset id and the owner address:
Name | Type | Description | Initial Value |
---|---|---|---|
assetId | bytes | Hash code of the asset. | 0x68746e... (see below) |
owner | address | Address of the current asset owner. | tz1M...ACw (see below) |
It stores 4 extra variables used to implement the transfer of ownership process:
Name | Type | Description | Initial Value |
---|---|---|---|
bestbidder | address | Address of the best bidder; it is equal to the owner address when asset is not for sale. | owner |
bestbid | tez | Best bid amount. | 0tz |
endofbid | option of date | Date of the end of bid. | none |
_state | int | Value is either 0 (not for sale) or 1 (for sale). | 0 (not for sale) |
Entrypoints
The ownership contract provides three entrypoints:
Name | Parameter(s) | Description |
---|---|---|
upforsale | minimum selling price | Called by current owner to open bid process. Resulting contract state is ForSale . |
bid | Called by anyone. It requires:
bestbidder and bestbid variables with new values; endofbid is incremented by 2 minutes. | |
claim | Called by anyone. It requires:
owner variable to the best bidder address. Contract state is set back to "not for sale". |