Skip to content
Documentation
API Reference
RPC API

RPC API

OpenMask uses the ton.send(args) method to wrap an RPC API.

The API is based on an interface exposed by all TON clients, along with a growing number of methods that may or may not be supported by other wallets.

Methods

ton_requestAccounts

Returns

string[] - An array of a single, TON address string.

Description

Requests that the user provides a TON address to be identified by. Returns a Promise that resolves to an array of TON address string. If the user denies the request, the Promise will reject with a Error.

The request causes a OpenMask popup to appear. You should only request the user's accounts in response to user action, such as a button click. You should always disable the button that caused the request to be dispatched, while the request is still pending.

If you can't retrieve the user's account(s), you should encourage the user to initiate an account request.

Example

document.getElementById('connectButton', connect);

function connect() {
  ton
    .send("ton_requestAccounts")
    .then(handleAccountsChanged)
    .catch((error) => {
        console.log('Please connect to OpenMask.');
    });
}

ton_requestWallets

Returns

object[] - An array of objects with wallet TON address, version and publicKey.

interface RequestWalletsOutput {
    address: string;
    publicKey: string;
    version:  "v2R1" | "v2R2" | "v3R1" | "v3R2" | "v4R1" | "v4R2";
}

Description

The method is equivalent to ton_requestAccounts but returns extra information about wallets. The method may be useful if the wallet is not deploy in the network and it is umpossible to load the public key from the web.

Example

document.getElementById('connectButton', connect);

function connect() {
  ton
    .send("ton_requestWallets")
    .then(console.log);
}


/** In the console:
    [{
        address: "EQCV4FC_GjwyRDx4RAfI9-f1z3Tfi6JBxEOHol8SUpI2xTxT"
        publicKey: "352f62f1f9d5c8ab5b1d7bdde41a42f94688d23936eebe1399fe60d8c1b62d2a"
        version: "v4R2"
    }]
 */

ton_getBalance

Parameters

  • void | undefined - balance for active address;
  • string - address to check for balance

Returns

string - balance in nanocoin/wei

Example


function handleBalance(balance) {
    console.log(String(Number(balance) / 1000000000))
}

ton.send("ton_getBalance")
    .then(handleBalance)
    .catch((error) => {
        console.error(error);
    });

ton.send("ton_getBalance", "EQDdTENo4SOc3ax3f86RuWnfLz5Sablz3fsyGvCA5uq3eUPG")
    .then(handleBalance)
    .catch((error) => {
        console.error(error);
    });

ton_sendTransaction

Parameters

  1. object - the data parameters
  2. string - the wallet address (optional)
interface TransactionParams {
    // Nanotons to send
    value: string;
    // Destination address
    to: string;
    // Type of Additional data (optional)
    dataType?: "hex" | "base64" | "boc" | undefined;
    // Additional data (optional)
    data?: string;
}

Returns

number - wallet the sequence number (seqno)

Description

Wallet the sequence number this is similar to the nonce on Ethereum and holds the sequence number of the last transaction executed (used to prevent replay attacks)

Use ton_confirmWalletSeqNo to get confirmation that transaction is completely done.

Learn more about Seqno-based wallets.

Example

const seqNo = await provider.send("ton_sendTransaction", {
    to: "UQDwLAVAK8Q2fRbYa-hHmiMb9mEE0psIwwyH-rsAkZx4h991",
    value: "100000000",
    data: "Comment",
});

ton_confirmWalletSeqNo

Parameters

  1. number - the wallet sequence number (seqno)
  2. string - the wallet address (optional)

Returns

Returns a Promise that resolves when the wallet sequence number would be more the passed seqNo.

Example

await provider.send("ton_confirmWalletSeqNo", seqNo, address);

wallet_getChain

Returns

string - the network name, for example mainnet or testnet

Description

Chain id string representing the current blockchain's network ID.

Example

ton.send("ton_getChain")
    .then(chainId => console.log({ chainId }))
    .catch((error) => {
        console.error(error);
    });

wallet_switchChain

Parameters

string - the chainId, for example mainnet or testnet

Returns

Returns a Promise that resolves when the wallet change the network.

Example

await provider.send("wallet_switchChain", "mainnet");

Learn example how to change the network.

wallet_watchAsset

Parameters

  1. object - the asset parameters one of JettonAssetParams or NftAssetParams
  2. string - the wallet address (optional)
interface JettonAssetParams {
    type: "jetton",
    // Jetton Minter Contract Address
    address: string,
    // Jettin name (optional)
    name?: string,
     // Jettin Symbol (optional)
    symbol?: string,
    // Jetton logo, url to image (optional)
    image?: string,
}

interface NftAssetParams {
    type: "nft",
    // NFT Contract Address
    address: string,
}

Returns

Returns a Promise that resolves with a boolean value, with mean that coin was add or reject in the wallet.

Example

await provider.send("wallet_watchAsset", {
    type: "jetton",
    address: "EQBXHCDdBA6Vgd2zi-yRpFk8m04vn3ROWYU9GRZfpvrim1M5",
});

Learn example how to offer asset.

ton_rawSign

  1. object - the raw data parameters
  2. string - the wallet address (optional)
interface RawSignParams {
    // String payload data in hex format
    data: string,
}

Returns

Returns a Promise that resolves with a string value, with is signatire for provided data.

Example

const signature = await provider.send("ton_rawSign", {
    data: "48656c6c6f20776f726c64",
});

ton_personalSign

  1. object - the utf8 data parameters
  2. string - the wallet address (optional)
interface PersonalSignParams {
    // String payload data in utf8 format
    data: string,
}

Returns

Returns a Promise that resolves with a string value, with is signatire for hexed data.

Example

const signature = await provider.send("ton_personalSign", {
    data: "Hello world",
});

ton_encryptMessage

  1. object - the utf8 data parameters
  2. message - the wallet address (optional)
interface EncryptMessageParams {
    // Base64 encoded value
    message: stirng;
    receiverPublicKey?: string | undefined;
}

Returns

Returns a Promise that resolves with a string value, with is encrypted message.

Example

const encryptMessage = await provider.send("ton_encryptMessage", {
    message: btoa("Hello World"),
});

ton_decryptMessage

  1. object - the utf8 data parameters
  2. message - the wallet address (optional)
interface DecryptMessageParams {
    // Encrypt message
    message: stirng;
    senderPublicKey?: string;
}

Returns

Returns a Promise that resolves with a string value, with is dencrypted message in base64 encoding.

Example

const result = await provider.send("ton_decryptMessage", {
    message: encryptMessage,
});

console.log(atob(result)) // "Hello World"

ton_deployContract

Parameters

  1. object - the contract parameters
  2. string - the wallet address (optional)
interface DeployParams {
    // Smart contract code hexadecimal string
    initCodeCell: string;
    // Smart contract initial data hexadecimal string
    initDataCell: string;
    // Initial mesasge hexadecimal string (optional)
    initMessageCell?: string;
    // Amount to funding smart contract in nanotons, to pay network and storage fee
    amount: string;
}

Returns

Returns a Promise that resolves with a object value.

interface DeployOutput {
    // SeqNo for wallet with run contract deployment
    walletSeqNo: number;
    // Address for newly deployed contract
    newContractAddress: string;
}

Example

Please read more about the example in the blog post. You may find information how to build contract code initCodeCell and generate initDataCell or initMessageCell. As well as send message to blockchain and verify result.