Skip to main content

Contract setup

The smart contract is at this location:

~/completium-dapp-miles/contract/miles_with_expiration.arl

The contract is written in Archetype language. Go to the Smart contract section for a detailed presentation.

The setup consists in deploying the contract and adding mile to the user account.

Origination#

Open the terminal and enter the following command line to originate (deploy) the smart contract is:

completium-cli deploy ./contract/miles_with_expiration.arl --named miles

The originate command triggers two operations:

  • the contract compilation to Michelson with archetype compiler
  • the Michelson contract origination with Tezos client

The contract may then be referred to as miles in future interactions.

If you are using the preset Gitpod environement, note that completium-cli is pre-installed with the admin account. See this section for more information.

The address of the newly originated contract is visible in the command output, as illustrated below:

Docusaurus with Keytar

A smart contract address starts with KT1. In the situation above, the new contract's address is KT19TYkVxnUb1m9DoWbSASqY6XQdVLQFCK8F.

You may got to Better call dev contract explorer to check it:

The new contract address needs to be set in the DApp's src/settings.js file:

/////////////////////////////////////////////////////////////////////////////// FIX ME// set new contract address/////////////////////////////////////////////////////////////////////////////export const  contractAddress = "KT1F5DqPwKJC9qeEjTgdEQKGGBZpcAv5DX86"

Add miles#

In order to provide miles to a user, the amdin must call the 'add' entry point of the contract.

If you don't have a user account, follow these instructions to get one.

The entry point signature is presented below:

entry add (ow                 : address,           newmile_id         : string,           newmile_amount     : int,           newmile_expiration : date) {   called by admin   effect {     ...   }}

Parameters are presented below:

ParameterValueDescription
owUSER_ADDRESSaddress of the miles' owner, for example '@tz1MZrh8CvYkp7BfLQMcm6mg5FvL5HRZfACw'
newmile_idUSER_ADDRESS + "_0"a unique identifier for the created miles, for example 'tz1MZrh8CvYkp7BfLQMcm6mg5FvL5HRZfACw_0'
newmile_amount20number of miles to create
newmile_expirationTOMORROWdate beyond which miles are expired, for example '2021-06-28'

where:

  • USER_ADDRESS is replaced by the DApp user account to receive the miles
  • TOMORROW is replaced by a date in the future, for example tomorrow

In the terminal enter the following command:

completium-cli call miles --entry add        --with '(<USER_ADDRESS>, "mileid", 20, 2021-06-28)'

Skip this step?#

It is possible to skip this phase and use the contract already deployed for the demo, and available at the following address:

KT1F5DqPwKJC9qeEjTgdEQKGGBZpcAv5DX86

Go to the use case section to know how to add miles for your user account.