TON contracts for Agorata
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
igor 86256c1adc dev: selling 2 years ago
build Init 2 years ago
contracts dev: selling 2 years ago
test dev: selling 2 years ago
.gitignore dev: selling 2 years ago
.gitmodules remove unnecessary submodule 2 years ago
LICENSE Init 2 years ago
README.md Update readme 2 years ago
package-lock.json dev: selling 2 years ago
package.json dev: selling 2 years ago
tsconfig.json Init 2 years ago

README.md

Agorata - Contracts

Created from the starter template for a new TON project - FunC contracts, JS tests, compilation and deployment scripts

Overview

main.fc contains the contract for domains with subdomain support. It is supposed to implement the stadarts for a domain, an NFT collection, and an NFT item.

What does this repo contain?

  • contracts/*.fc - Smart contracts for TON blockchain written in FunC language
  • test/*.spec.ts - Test suite for the contracts in TypeScript running on Mocha test runner
  • build/_build.ts - Build script to compile the FunC code to Fift and TVM opcodes
  • build/_deploy.ts - Deploy script to deploy the compiled code to TON mainnet (or testnet)
  • build/_setup.ts - Setup script to install build dependencies (used primarily for Glitch.com support)

There is no one official way to develop smart contracts for TON. Every developer has their own best practices. This setup is definitely opinionated and some developers may not appreciate the choices made. Nevertheless, we stand by every choice made here and believe that this is the optimal setup to develop fully tested contracts in the most seamless way possible.

Some of the opinionated choices made here include:

  • Cross platform support - allow developers to work on Mac M1, Mac Intel, Windows or Linux
  • Strong belief in tests - contracts often manage money - they must be developed under high scrutiny
  • Clear and documented code to help users audit the contracts sources and understand what they do
  • Reliance on modern TypeScript to develop clean and typed scripts and tests in a modern framework
  • Reliance on TypeScript for deployment instead of working with fift CLI tools - it's simply easier
  • Tests are executed in JavaScript with TVM in web-assembly - a great balance of speed and convenience
  • Following of the TON contract best practices appearing in the official docs

Dependencies and requirements

To setup your local machine for development, please make sure you have the following:

  • A modern version of Node.js (version 16.15.0 or later)
    • Installation instructions can be found here
    • Run in terminal node -v to verify your installation, the project was tested on v17.3.0
  • The func CLI tool (FunC compiler)
    • Installation instructions can be found here
    • Run in terminal func -V to verify your installation
  • The fift CLI tool
    • Installation instructions can be found here
    • Don't forget to set the FIFTPATH env variable as part of the installation above
    • Run in terminal fift -V and fift to verify your installation
  • A decent IDE with FunC and TypeScript support

Once your local machine is ready, install the project:

  • Git clone the repo locally and rename the directory to your own project name
  • In the root repo dir, run in terminal npm install

Development instructions

  • Write code

    • FunC contracts are located in contracts/*.fc
      • Standalone root contracts are located in contracts/*.fc
      • Shared imports (when breaking code to multiple files) are in contracts/imports/*.fc
      • Contract-specific imports that aren't shared are in contracts/imports/mycontract/*.fc
    • Each contract may have optional but recommended auxiliary files:
      • TL-B file defining the encoding of its data and message ops in contracts/mycontract.tld
      • TypeScript file that implements the encoding of its data and message ops in contracts/mycontract.ts
    • Tests in TypeScript are located in test/*.spec.ts
  • Build

    • In the root repo dir, run in terminal npm run build
    • Compilation errors will appear on screen
    • Resulting build artifacts include:
      • mycontract.fif - Fift file result of compilation (not very useful by itself)
      • mycontract.compiled.json - the binary code cell of the compiled contract (for deployment). Saved in a hex format within a json file to support webapp imports
  • Test

    • In the root repo dir, run in terminal npm run test
    • Don't forget to build (or rebuild) before running tests
    • Tests are running inside Node.js by running TVM in web-assembly using ton-contract-executor
  • Deploy

    • Make sure all contracts are built and your setup is ready to deploy:
      • Each contract to deploy should have a script build/mycontract.deploy.ts to return its init data cell
      • The deployment wallet is configured in .env (created automatically if not exists), with contents:
        DEPLOYER_MNEMONIC="mad nation chief flavor ..." (24 secret words)
    • To deploy to mainnet (production), run in terminal npm run deploy
      • To deploy to testnet instead (where TON coins are free), run npm run deploy:testnet
      • Follow the on-screen instructions of the deploy script

License

MIT