Blueprint

repository·master·Indexed 20 days ago

https://github.com/ton-org/blueprint

A comprehensive development environment for the TON blockchain used to write, test, and deploy smart contracts in Tolk, FunC, and Tact. It provides a CLI for scaffolding projects, building contracts, running TypeScript tests via the Sandbox library, and deploying to mainnet or testnet using various methods including TON Connect and Mnemonics.

Tokens
14.7K
Snippets
65
Records
81
Agent score
70%

What's inside @ton/blueprint

  1. Understand the project directory structure

    master

    A standard Blueprint project follows this layout:

    • contracts/: Source code for smart contracts (FunC) and their dependencies.
      • Standalone root contracts: contracts/*.fc
      • Shared imports: contracts/imports/*.fc
    • wrappers/: TypeScript wrapper classes (implementing Contract from @ton/core) for interacting with contracts, including [de]serialization and compilation logic.
      • Builder configs: wrappers/*.compile.ts
    • tests/: TypeScript tests for the contracts (typically using wrappers).
    • scripts/: Project scripts, primarily deployment scripts.
    • build/: Contains compiled contract artifacts (e.g., build/*.compiled.json).
  2. Project directory structure

    master

    A Blueprint project follows a specific directory structure:

    • contracts/: Source code for all smart contracts and their imports.
    • wrappers/: TypeScript interface classes for contracts (except Tact). Each wrapper implements the Contract interface from @ton/core and is used by tests and client code to interact with contracts via message (de)serialization and getters.
    • compilables/: Compilation scripts for contracts.
    • tests/: TypeScript test suite (uses Sandbox for in-process testing).
    • scripts/: Deployment scripts and other scripts for interacting with live contracts.
    • build/: Compilation artifacts (e.g., .compiled.json, Tact-generated files, or Fift output).
  3. Run contract tests and gas reports

    master

    Tests run in Node.js using the sandbox library (running TVM in WebAssembly). Always ensure you build your contracts before running tests.

    • Run tests: yarn test
    • Generate gas metric report: yarn gas-report
    • Save a gas metric snapshot: yarn gas-snapshot '<label name>'
    yarn test
  4. Build smart contracts

    master

    To build your contracts, you must have a compilation script located at compilables/<CONTRACT>.compile.ts.

    Interactive build:

    npx blueprint build
    # or
    yarn blueprint build

    Non-interactive build: To build a specific contract:

    npx blueprint build <CONTRACT>
    # or
    yarn blueprint build <CONTRACT>

    To build all contracts:

    yarn blueprint build --all

    Build results are stored in build/<CONTRACT>.compiled.json.

    yarn blueprint build counter
  5. Create and rename contracts

    master

    Blueprint provides CLI commands to scaffold new contracts or rename existing ones.

    Create a contract: Interactive:

    npx blueprint create

    Non-interactive:

    npx blueprint create <CONTRACT> --type <TYPE>
    # Example:
    # yarn blueprint create MyNewContract --type tolk-empty

    Rename a contract: Interactive:

    npx blueprint rename

    Non-interactive:

    npx blueprint rename <OLD_NAME> <NEW_NAME>
    yarn blueprint create MyNewContract --type tolk-empty
  6. Run contract test suites

    master

    Run your TypeScript tests using the Blueprint CLI or your package manager.

    Using Blueprint:

    npx blueprint test
    # or
    yarn blueprint test

    Using npm/yarn:

    npm test
    # or
    yarn test

    Run specific contract tests:

    yarn test <CONTRACT>

    Collect coverage: To generate a coverage report, run:

    blueprint test --coverage

    Coverage results will be placed in the coverage directory.

    yarn test counter
  7. Benchmark and gas reporting

    master

    You can collect performance metrics and gas reports for your contracts using the Sandbox integration.

    Collect metrics snapshot:

    npx blueprint snapshot [--label=<comment>|-l <comment>]

    Compare metrics with gas report:

    npx blueprint test --gas-report|-g
    npx blueprint snapshot --label="my-benchmark"
  8. Quick start with Blueprint

    master

    To create a new TON development project using Blueprint, run the following command and follow the interactive on-screen instructions:

    npm create ton@latest

    After the project is created, navigate into the project directory and install the dependencies using npm install or yarn install.

  9. Verify contracts using a custom network

    master

    When verifying contracts on a custom network, you must specify the network details via CLI flags or config. Crucially, the custom type MUST be specified as either mainnet or testnet when verifying.

    Example CLI command:

    npx blueprint verify --custom https://toncenter.com/api/v2/jsonRPC --custom-version v2 --custom-type mainnet --custom-key YOUR_API_KEY --compiler-version 0.4.4-newops.1
  10. Deploy a smart contract

    master

    Deployment can be performed interactively or via CLI flags. Supported deployment methods include TON Connect, ton:// deep links/QR codes, Tonhub wallet, or Mnemonics.

    Interactive mode: Run yarn blueprint run and follow the prompts to select the contract, network (mainnet/testnet), and deployment method.

    Non-interactive mode: Use the following syntax: yarn blueprint run <CONTRACT> --<NETWORK> --<DEPLOY_METHOD>

    Example:

    yarn blueprint run pingpong --mainnet --tonconnect