From a8cd1e28c23282bb6ef56cf8083b0dd09de3f5cf Mon Sep 17 00:00:00 2001 From: Aliaksandr Bahdanau Date: Tue, 27 Aug 2024 12:53:33 +0300 Subject: [PATCH] add info about contract deploy --- docs/develop/dapps/ton-connect/react.mdx | 37 +++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/docs/develop/dapps/ton-connect/react.mdx b/docs/develop/dapps/ton-connect/react.mdx index a768b7f982..1774c7d312 100644 --- a/docs/develop/dapps/ton-connect/react.mdx +++ b/docs/develop/dapps/ton-connect/react.mdx @@ -354,6 +354,41 @@ const [tonConnectUI] = useTonConnectUI(); await tonConnectUI.disconnect(); ``` +#### Deploying contract + +Deploying contract using TonConnect is pretty straightforward. You just need to obtain contract code and state init, store it as a cell and send transaction with `stateInit` field provided. + +Note, that `CONTRACT_CODE` and `CONTRACT_INIT_DATA` may be found in wrappers. + +```typescript +import { beginCell, Cell, contractAddress, StateInit, storeStateInit } from '@ton/core'; + +const [tonConnectUI] = useTonConnectUI(); + +const init = { + code: Cell.fromBase64(''), + data: Cell.fromBase64('') +} satisfies StateInit; + +const stateInit = beginCell() + .store(storeStateInit(init)) + .endCell(); + +const address = contractAddress(0, init); + +await tonConnectUI.sendTransaction({ + validUntil: Date.now() + 5 * 60 * 1000, // 5 minutes + messages: [ + { + address: address.toRawString(), + amount: '5000000', + stateInit: stateInit.toBoc().toString('base64') + } + ] +}); + +``` + ## Wrappers Wrappers are classes that simplify interaction with the contract, allowing you to work without concerning yourself with the underlying details. @@ -549,7 +584,7 @@ const getCounterInstance = async () => { // import { // createApi, // } from "@ton-community/assets-sdk"; - + // const NETWORK = "testnet"; // const client = await createApi(NETWORK);