Skip to main content
TON Sandbox (@ton/sandbox) is a local blockchain emulator that allows you to test smart contracts from TypeScript, without deploying them to a real network, and without running a blockchain node. It provides a complete testing environment that closely mimics the behavior of the actual TON blockchain. Blueprint project template already includes the @ton/sandbox dependency. The companion @ton/test-utils helper library provides matchers for writing tests with Jest. This guide covers everything you need to know about writing, running, and debugging tests for your smart contracts. For other programming languages consult documentation of corresponding SDKs.

Sandbox vs real network

Sandbox limitations

While Sandbox closely emulates the real network, there are some differences to be aware of:
  • Time-dependent contracts: Sandbox time is controlled, not real-time
  • External dependencies: Cannot interact with real external contracts, but can get their state and emulate them
  • Blockchain imitation: Because there is no concept of blocks in Sandbox, things like sharding do not work.

Writing tests

Blueprint uses Jest as the default testing framework, providing powerful assertion capabilities and excellent TypeScript support.

Basic test setup

Every Blueprint project includes a test template. Here’s the standard structure:
tests/MyContract.spec.ts

Test isolation

Each test should include a fresh Blockchain instance to ensure: Test isolation
  • No state leakage between tests
  • Predictable initial conditions
  • Independent contract deployments
Clean environment
  • Fresh treasury wallets
  • Reset logical time and configuration
  • Clear transaction history

Understanding transaction results

When you send a message to a contract, you receive a SendMessageResult containing:

Transaction matchers

Blueprint provides powerful matchers for validating transactions:

Running tests

Common pitfalls

Debugging checklist

When tests fail, check these common issues:
  • ✅ Contract is properly deployed before testing
  • ✅ Treasury has sufficient balance for operations
  • ✅ Transaction matchers use correct field names
  • ✅ Exit codes match expected error conditions
  • ✅ Message bodies are correctly formatted
  • ✅ Time-sensitive operations account for blockchain time

Next steps

Comprehensive Testing Advanced Topics Debugging Resources The Sandbox testing framework provides everything you need to thoroughly test your TON smart contracts. Start with basic deployment tests, then expand to cover all your contract’s functionality with comprehensive positive and negative test cases.