Zen Protocol Documentation
WebsiteTelegramBlogForum
  • Zen Protocol Docs
  • Apps
    • Headless Full Node
      • Full Node NPM Package
      • Build from Source
      • CLI
      • API
        • Wallet
        • Contracts
        • General
        • Blockchain
        • AddressDB
      • Deploy
        • Systemd
        • Shell script
        • Docker
      • Technical Model
      • AddressDB
    • Wallet
      • Desktop Wallet
        • Installers
      • Web Wallet
        • Run Locally
      • Wallet User Guide
        • Connect a Wallet
          • Create a Wallet
          • Import a Wallet
          • Watch Mode
        • My Wallet
          • Navigation Bar
          • Portfolio
          • Receive
          • Send / Execute
          • Transaction History
        • Contracts
          • Active Contracts
          • Execute a Contract
            • Message Body Field
          • Extend a Contract
          • Activate a Contract
        • Voting
          • Common Goods Pool
            • Generating a Ballot ID
          • Governance
        • Signer
        • Settings
          • Account Settings
          • Node Connectivity
      • Deprecated Desktop Wallet
        • Executable Installers
        • Wallet Structure
          • Video Tutorials
    • Explorer
    • Zen.js
      • Payment Processing
    • Oracle
      • Oracle GUI
      • Oracle Service
      • Oracle's API
      • Deploy
        • Systemd
        • Docker
      • How the Oracle contract works
      • How to create an Attestation token
    • Dex
      • Dex User Guide
        • Traded Pairs
        • Search Pairs
        • Order Book
        • Operations
        • My Wallet
        • Settings
      • How DEX contract works
    • Fixed Payout
      • Fixed Payout Generator User Guide
        • Issue
        • Redeem
        • Cancel
        • Verify
        • Settings
      • How the FP Contract works
      • How are the asset named?
  • Smart Contracts
  • Contract Structure
  • Contract Cost
  • Contract Activation
  • Contract Examples
  • Smart Contracts SDK
  • Contracts Language ZF*
  • Named Token Tutorial
  • Consensus
  • Common Goods Pool
  • Block Validation
  • Transaction Validation
  • Serialization
  • Use Cases
    • Create Unsigned Transaction
    • Secure Sign Transaction
    • Cold Storage using Full Node
  • Troubleshooting
    • Responsible Disclosure
    • Bug Bounty
    • Known Bugs
  • For Miners
    • Pools
    • GPU Mining
    • GPU Bounties
  • Check Crowdsale Contribution
  • Alpha call option
Powered by GitBook
On this page
  • Contract Structure
  • Parameters
  • Output

Contract Structure

Contract Structure

Each contract must contain 2 functions: main and cf.

The main function is run whenever a contract is used within a transaction.

The function will run both at the validation and at the generation of the transaction.

The structure of the main function is:

main
    ( txSkel      : Zen.Types.txSkeleton  )
    ( context     : Zen.Types.context     )
    ( contractId  : Zen.Types.contractId  )
    ( command     : string                )
    ( sender      : Zen.Types.sender      )
    ( messageBody : option Zen.Types.data )
    ( wallet      : Zen.Types.wallet      )
    ( state       : option Zen.Types.data )
    : Zen.Types.contractResult `Zen.Cost.t` n

where n must be an expression which evaluates to a natural number (nat).

Parameters

  • txSkel : Zen.Types.txSkeleton : The partial transaction supplied as input to the contract.

  • context : Zen.Types.context : The blockchain context of the transaction, given by blockNumber (unsigned 32 bit integer), and timestamp - which is the UNIX Epoch time (unsigned 64 bit integer) of the block creation.

  • contractId : Zen.Types.contractId : The contract identifier. (version, hash)

  • command : string : String that the contract may use. Contains a command which tells the contract what to do. For example:

match command with
| "redeem" -> redeem txSkeleton contractId returnAddress wallet
| "buy"    -> buy txSkeleton contractId returnAddress
  • sender : Zen.Types.sender : The sender identity. Can be any of the following:

    • Contract of Zen.Types.contractId: a contract, given by its ID

    • PK of Zen.Types.publicKey: a Public key

    • Anonymous: an anonymous sender

  • messageBody : option Zen.Types.data : The transaction may carry a message which can be any of the following:

    • Byte: of FStar.UInt8.t: 8 bit unsigned integer

    • U32 of FStar.UInt32.t: 32 bit unsigned integer

    • U64 of FStar.UInt64.t: 64 bit unsigned integer

    • I64 of FStar.Int64.t: 64 bit signed integer

    • ByteArray of Zen.Array.t FStar.UInt8.t: array of 8 bit unsigned integer

    • String of string: FStar.prims

    • Hash of Zen.Types.hash: 256-bit hash value

    • Lock of Zen.Types.lock: Lock

    • Signature of Zen.Types.signature: Signature

    • PublicKey of Zen.Types.publicKey: Public key

    • Collection of Zen.Types.dataCollection: Data collection

  • wallet : Zen.Types.wallet : Contains all the transaction inputs that were previously locked to the contract. In order for a contract to spend its own funds they need to come from contract wallet.

  • state : option Zen.Types.data : The contract current state. Can be either Some data (as the message body) or None.

Output

The output of the contract is of the record type Zen.Types.contractReturn which has 3 fields:

  • state : Zen.Types.stateUpdate State update. Can be any of the following:

    • Delete - Delete the current state, resetting it to None

    • NoChange - Keeping the current state as it is, with no change.

    • Update of Zen.Types.data - Change the state to be the new given data.

  • tx : Zen.Types.txSkeleton The generated transaction structure.

  • message : option Zen.Types.message An optional message for invoking another contract. This is a record type which has 3 fields:

    • recipient: Zen.Types.contractId - The recipient contract.

    • command: string - The command given to the recipient contract.

    • body: option Zen.Types.data - The message body of given to the recipient contract.

PreviousHow are the asset named?NextContract Cost

Last updated 4 years ago