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
  • Active Contract Set
  • Contract ID
  • Activate Contract
  • Execute Contract
  • Extend Contract
  1. Apps
  2. Headless Full Node
  3. API

Contracts

Active Contract Set

GET http://127.0.0.1:31567/contract/active

Returns all currently active contracts. May not be accurate until the blockchain is fully synced.

[
    {
        "contractHash": "55be2edd1e537869cce832bd014aa1e3251aba651c5c3f38f70db86417faa9c4",
        "address": "tc1q2klzahg72duxnn8gx27szj4puvj34wn9r3wr7w8hpkuxg9l648zqhc76xa",
        "expire": 19375,
        "code": "(* NAME_START: Example Token :NAME_END *)\nopen Zen.Types\nopen Zen.Vector\nopen Zen.Base\nopen Zen.Cost\nopen Zen.Asset\nopen Zen.Data\n\nmodule ET = Zen.ErrorT\nmodule OT = Zen.OptionT\nmodule Tx = Zen.TxSkeleton\nmodule CR = Zen.ContractResult.NoMessage\n\nlet buy txSkeleton contractHash returnAddress =\n  let! tokens = Tx.getAvailableTokens zenAsset txSkeleton in\n\n  let! contractAsset = getDefault contractHash in\n\n  let! txSkeleton =\n    Tx.lockToContract zenAsset tokens contractHash txSkeleton\n    >>= Tx.mint tokens contractAsset\n    >>= Tx.lockToAddress contractAsset tokens returnAddress in\n\n  CR.ret txSkeleton\n\nlet redeem txSkeleton contractHash returnAddress wallet =\n  let! contractAsset = getDefault contractHash in\n  let! tokens = Tx.getAvailableTokens contractAsset txSkeleton in\n\n  let! txSkeleton =\n    Tx.destroy tokens contractAsset txSkeleton\n    >>= Tx.lockToAddress zenAsset tokens returnAddress\n    >>= Tx.fromWallet zenAsset tokens contractHash wallet in\n\n  CR.ofOption \"contract doesn't have enough zens to pay you\" txSkeleton\n\nval main: txSkeleton -> hash -> string -> option data -> wallet:wallet -> cost (result (txSkeleton ** option message))  (2 + 66 + (64 + (64 + (64 + 64 + (Zen.Wallet.size wallet * 128 + 192) + 0)) + 25) + 29)\nlet main txSkeleton contractHash command data wallet =\n  let! returnAddress = data >!> tryDict >?> tryFindLock \"returnAddress\" in\n\n  match returnAddress with\n  | Some returnAddress ->\n      if command = \"redeem\" then\n        redeem txSkeleton contractHash returnAddress wallet\n      else if command = \"\" || command = \"buy\" then\n        buy txSkeleton contractHash returnAddress\n        |> autoInc\n      else\n        ET.autoFailw \"unsupported command\"\n  | None ->\n      ET.autoFailw \"returnAddress is required\"\n\nval cf: txSkeleton -> string -> option data -> wallet -> cost nat 24\nlet cf _ _ _ wallet = ret  (2 + 66 + (64 + (64 + (64 + 64 + (Zen.Wallet.size wallet * 128 + 192) + 0)) + 25) + 29)"
    },
    {
        "contractHash": "55be2edd1e537869cce832bd014aa1e3251aba651c5c3f38f70db86417faa9c4",
        "address": "tc1q2klzahg72duxnn8gx27szj4puvj34wn9r3wr7w8hpkuxg9l648zqhc76xa",
        "expire": 19375,
        "code": "(* NAME_START: Example Token :NAME_END *)\nopen Zen.Types\nopen Zen.Vector\nopen Zen.Base\nopen Zen.Cost\nopen Zen.Asset\nopen Zen.Data\n\nmodule ET = Zen.ErrorT\nmodule OT = Zen.OptionT\nmodule Tx = Zen.TxSkeleton\nmodule CR = Zen.ContractResult.NoMessage\n\nlet buy txSkeleton contractHash returnAddress =\n  let! tokens = Tx.getAvailableTokens zenAsset txSkeleton in\n\n  let! contractAsset = getDefault contractHash in\n\n  let! txSkeleton =\n    Tx.lockToContract zenAsset tokens contractHash txSkeleton\n    >>= Tx.mint tokens contractAsset\n    >>= Tx.lockToAddress contractAsset tokens returnAddress in\n\n  CR.ret txSkeleton\n\nlet redeem txSkeleton contractHash returnAddress wallet =\n  let! contractAsset = getDefault contractHash in\n  let! tokens = Tx.getAvailableTokens contractAsset txSkeleton in\n\n  let! txSkeleton =\n    Tx.destroy tokens contractAsset txSkeleton\n    >>= Tx.lockToAddress zenAsset tokens returnAddress\n    >>= Tx.fromWallet zenAsset tokens contractHash wallet in\n\n  CR.ofOption \"contract doesn't have enough zens to pay you\" txSkeleton\n\nval main: txSkeleton -> hash -> string -> option data -> wallet:wallet -> cost (result (txSkeleton ** option message))  (2 + 66 + (64 + (64 + (64 + 64 + (Zen.Wallet.size wallet * 128 + 192) + 0)) + 25) + 29)\nlet main txSkeleton contractHash command data wallet =\n  let! returnAddress = data >!> tryDict >?> tryFindLock \"returnAddress\" in\n\n  match returnAddress with\n  | Some returnAddress ->\n      if command = \"redeem\" then\n        redeem txSkeleton contractHash returnAddress wallet\n      else if command = \"\" || command = \"buy\" then\n        buy txSkeleton contractHash returnAddress\n        |> autoInc\n      else\n        ET.autoFailw \"unsupported command\"\n  | None ->\n      ET.autoFailw \"returnAddress is required\"\n\nval cf: txSkeleton -> string -> option data -> wallet -> cost nat 24\nlet cf _ _ _ wallet = ret  (2 + 66 + (64 + (64 + (64 + 64 + (Zen.Wallet.size wallet * 128 + 192) + 0)) + 25) + 29)"
    }
]

Contract ID

GET http://127.0.0.1:31567/contract/contractId

Get a contract identifier from a contract address.

Path Parameters

Name
Type
Description

address*

string

address of the contract

00000000e89738718a802a7d217941882efe8e585e20b20901391bc37af25fac2f22c8ab
invalid address map
  [("address",
    "notExistingContractAddress")]

Activate Contract

POST http://127.0.0.1:31567/wallet/contract/activate

This how you activate a contract

Request Body

Name
Type
Description

password

string

wallet password

numberOfBlocks

number

The number of blocks you want to activate your contract for

code

string

Send valid fstar code, for example: let main _ _ _ _ _ _ _ _ = Zen.ResultT.failw \"This contract does nothing\"\nlet cf _ _ _ _ _ _ _ = Zen.Cost.ret (1 <: nat)

{
    "address": "ctzn1qqqqqqqym4kfe8y5qg5tazkgjwn4qpesj05x6mqsvd5auwmzkhhs444fnkvwxhahr",
    "contractId": "000000009bad939392804517d1591274ea00e6127d0dad820c6d3bc76c56bde15ad533b3"
}

Execute Contract

POST http://127.0.0.1:31567/wallet/contract/execute

Run a smart contract with parameters

Request Body

Name
Type
Description

options*

string

add sign and return address here if needed

sign*

string

the derivation path for the execution of the contract

password*

string

wallet password

returnAddress*

boolean

allows the contract to automatically send funds back to in case it needs to.

messageBody*

string

send the contract some data

address*

string

The contract address

command*

string

Trigger one of the functions in the contract

spends*

array

an array of outputs

5222c826d8d403636a75f48fd91d7d177be6efbf04ac266f3822322733e938ad

Extend Contract

POST http://127.0.0.1:31567/wallet/contract/extend

This is to extend a contract

Request Body

Name
Type
Description

password*

string

wallet password

numberOfBlocks*

string

Number of block until when the contract will be active

contractId*

string

ID of the contract

5222c826d8d403636a75f48fd91d7d177be6efbf04ac266f3822322733e938ad

PreviousWalletNextGeneral

Last updated 1 year ago