π¨Compilation and deploy of the TON smart contract
How to compile and deploy smart contract on TON Blockchain using javascript?
npm i -D ton ton-compiler tweetnaclimport { promises } from 'fs'
import { Address, Cell, CellMessage, contractAddress, serializeDict, TonClient } from 'ton'
import { compileFunc } from 'ton-compiler'
import nacl from 'tweetnacl'const { publicKey, secretKey } = nacl.sign.keyPair()
await promises.writeFile('key.pk', Buffer.from(secretKey))// You may find slot.fc content here https://gist.github.com/ton-solutions/c300d0ebb0a3ee920c8e8b310a451e29
const funcSource = (await promises.readFile('slot.fc')).toString('utf-8')
const compilationResult = await compileFunc(funcSource)
const initialCode = Cell.fromBoc(compilationResult.cell)[0]const reelsCount = 5
const symbolsCount = 8
const payTable = new Map([
['2111', 50],
['221', 100],
['311', 200],
['32', 250],
['41', 2000],
['5', 5000]
])
const slotParams = new Cell()
slotParams.bits.writeUint(symbolsCount, 8)
slotParams.bits.writeUint(reelsCount, 8)
slotParams.bits.writeBit(true)
const payTableCell = serializeDict(payTable, 32, (value, cell) => {
cell.bits.writeUint(value, 32)
})
slotParams.refs.push(payTableCell)
let initialData = new Cell()
// seq_no
initialData.bits.writeUint(0, 32)
// Owner address
initialData.bits.writeAddress(Address.parse('<YOUR_ADDRESS>'))
// Deployer public key
initialData.bits.writeBuffer(Buffer.from(publicKey))
initialData = initialData.withReference(slotParams)Last updated