TON
The Open Network (TON) is a decentralized and open internet, created by the community using a technology designed by Telegram.
Setting up a wallet
Install the Tonkeeper wallet extension in your browser and create your wallet. Then export your recovery phrase by going to Settings > Recovery Phrase
. Enter your password and save your phrase.
Creating the SDK instance
You need a HTTP endpoint provider to access the TON network. We'll use the endpoint provided by Orbs.com for that.
Install the @orbs-network/ton-access
package in your project to get started.
yarn add @orbs-network/ton-access
Then create the SDK instance as follows:
import { TON } from "@kynesyslabs/demosdk/xm-websdk"
import { getHttpEndpoint } from "@orbs-network/ton-access"
// Get the rpc url
const endpoint = await getHttpEndpoint({
network: "testnet",
})
const instance = await TON.create(endpoint)
Connecting your wallet
You can connect your wallet using a mnemonic as follows:
await instance.connectWallet("wall park wife ...")
Getting your address
You can get your wallet address as follows:
const address = instance.getAddress()
Creating a transaction
Now you can create a signed TON transfer transaction.
const tx = await instance.prepareTransfer(
"EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N",
"1",
)
The tx
will be a signed BOC buffer that can be sent to a DEMOS node for broadcasting.
Creating multiple transactions
You can create multiple transfer transactions using the prepareTransfers
method.
const transfers = [
{
address: "EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N",
amount: "1",
},
{
address: "EQCD39VS5jcptHL8vMjEXrzGaRcCVYto7HUn4bpAOg8xqB2N",
amount: "1",
},
]
const txs = await instance.prepareTransfers(transfers)
Signing Messages
const message = "Hello, world!"
// Signing
const signature = await instance.signMessage(message)
// Verifying signature
const verified = await instance.verifyMessage(
message,
signature,
instance.wallet.publicKey.toString("hex"),
)
expect(verified).toBe(true)
Cleaning up
You can remove your wallet and RPC connections as follows:
await instance.disconnect()
Hacking
The DEMOS TON sdk is built on top of the TonJs library, and only provides a limited set of methods to interact with the TON blockchain.
You can access the underlying TonJs objects to have more control over the transactions and interactions with the blockchain.
Here is a list of the objects you can access:
Resources
Ton web JS client
API Reference
https://kynesyslabs.github.io/demosdk-api-ref/classes/xmwebsdk.TON.html
Last updated