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 --parameters '{ "admin" : "tz1h4CiqWxNe4UxSpkwXy617RM6DaK6NU76P" }'

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

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 = "KT1XpM1f6cq8cy8m8WV9xSsE5nBix2DzTYmx"

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 '@tz1h4CiqWxNe4UxSpkwXy617RM6DaK6NU76P'
newmile_idUSER_ADDRESS + "_0"a unique identifier for the created miles, for example 'tz1h4CiqWxNe4UxSpkwXy617RM6DaK6NU76P_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 --arg '{ "ow":"tz1hyc1CRQpjskJUUaGrh85UZXPi6kU4JuGd", "newmile_id":"id1", "newmile_expiration":"2022-12-25"  }'
warning

Replace tz1hyc1CRQpjskJUUaGrh85UZXPi6kU4JuGd in the command above with your user account address.

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:

KT1XpM1f6cq8cy8m8WV9xSsE5nBix2DzTYmx

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