npm create ton@latest
.
Contract creation
Use Blueprint to create a new contract.Interactive mode
To launch a guided prompt to create a contract step by step, use:Non-interactive mode
To create a contract without prompts, provide the contract name and template type:<CONTRACT>
- contract name<TYPE>
- template type, e.g., tolk-empty, func-empty, tact-empty, tolk-counter, func-counter, tact-counter
Contract code writing
After creation, contracts are placed in thecontracts/
folder.
Each file uses the extension that matches its language.
For example, creating a Tolk contract MyNewContract
results in contracts/my_new_contract.tolk
.
Building
Blueprint compiles your contracts into build artifacts.Interactive mode
Run without arguments to select contracts from a prompt:Non-interactive mode
Specify a contract name or use flags to skip prompts:Compiled artifacts
Compiled outputs are stored in thebuild/
directory.
-
build/<CONTRACT>.compiled.json
- serialized contract representation used for deployment and testing. Each file contains three fields:hash
— hash of the compiled contract code in hexadecimal format.hashBase64
— the same hash encoded in Base64.hex
— the compiled contract code in hexadecimal form.
<CONTRACT>.compiled.json -
build/<CONTRACT>/<CONTRACT>.fif
— Fift code derived from the contract.
Wrappers
Wrappers are TypeScript classes that you write to interact with your smart contracts. They act as a bridge between your application code and the blockchain, encapsulating contract deployment, message sending, and data retrieval logic. Each wrapper implements theContract
interface from @ton/core
.
When you create a new contract with Blueprint, you need to write your own wrapper class in the wrappers/
folder to define how your application will interact with the contract.
Naming ConventionMethods that send messages should start with
send
(e.g., sendDeploy
, sendIncrement
), and methods that read data should start with get
(e.g., getCounter
).This convention works seamlessly with open()
method, which automatically provides the ContractProvider
as the first argument to your wrapper methods.Static creating methods
Wrappers typically include two main static methods for creating contract instances:createFromAddress(address: Address)
Creates a wrapper instance for an already deployed contract using its address. This method is used when you want to interact with an existing contract on the blockchain.
./wrappers/Counter.ts
createFromConfig(config, code, workchain)
Creates a wrapper instance for a new contract that hasn’t been deployed yet. This method calculates the contract’s future address based on its initial state and code.
./wrappers/Counter.ts
config
- Initial configuration data for your contractcode
- Compiled contract code (usually loaded from build artifacts)workchain
- workchain ID (0 for basechain, -1 for masterchain)
Contracts created with
createFromAddress()
cannot be deployed since they lack the init
data required for deployment. Use createFromConfig()
for new contracts that need to be deployed.Sending messages
Message sending methods allow your application to trigger contract execution by sending internal or external messages. These methods handle the construction of message bodies and transaction parameters. All sending methods follow a similar pattern and should start withsend
:
./wrappers/Counter.ts
provider
-ContractProvider
instance that handles blockchain communicationvia
-Sender
object representing the transaction senderopts
- Options object containing transaction value and method-specific parameters
Calling get methods
Get methods allow you to read data from smart contracts without creating transactions. These methods are read-only operations that query the contract’s current state. All get methods should start withget
and return a Promise:
./wrappers/Counter.ts
Complete example
./wrappers/Counter.ts