Skip to content
Documentation
Sending Transactions

Sending Transactions

Transactions are a formal action on a blockchain. They are always initiated in OpenMask with a call to the ton_sendTransaction method. They can involve a simple sending of TON, may result in sending tokens, creating a new smart contract, or changing state on the blockchain in any number of ways. They are always initiated by a signature from an external account, or a simple key pair.

In OpenMask, using the ton.send method directly, sending a transaction will involve composing an options object like this:

const params = {
    to: "EQCV4FC_GjwyRDx4RAfI9-f1z3Tfi6JBxEOHol8SUpI2xTxT",
    value: "100000000",
    data: "Donate",
}

const seqNo = await provider.send("ton_sendTransaction", [params]);

Example

OpenMask donate address: "EQCV4FC_GjwyRDx4RAfI9-f1z3Tfi6JBxEOHol8SUpI2xTxT"
export default () => {
  const [disabled, setDisabled] = useState(false);
  const [isSent, setSent] = useState(false);
  const [isConfirm, setConfirm] = useState(false);

  const send = async () => {
    const provider = window.ton;

    console.log("isOpenMask=", provider.isOpenMask);
    setDisabled(true);
    try {
      await provider.send("ton_requestAccounts");

      const seqNo = await provider.send("ton_sendTransaction", [{
        to: "EQCV4FC_GjwyRDx4RAfI9-f1z3Tfi6JBxEOHol8SUpI2xTxT",
        value: "100000000",
        data: "Donate",
      }]);
      setSent(true);
      await provider.send("ton_confirmWalletSeqNo", [seqNo]);
      setConfirm(true);
    } catch (e) {
      console.error(e);
    } finally {
      setDisabled(false);
    }
  };

  return (
    <div>
      <div>
        OpenMask donate address:
        "EQCV4FC_GjwyRDx4RAfI9-f1z3Tfi6JBxEOHol8SUpI2xTxT"
      </div>
      <button disabled={disabled} onClick={send}>
        Send 0.1 TON
      </button>
      {isSent && (
        <div>
          {isConfirm
            ? "Success. Transaction confirm!"
            : "Transaction Pending... ~15 sec"}
        </div>
      )}
    </div>
  );
};

Transaction Parameters

to

Destination TON address. Required for transactions with a recipient (all transactions except for contract creation).

value

Value of the network's native currency to send. Value is denominated in nanoTONs, in gwei, which is 1e-9 TON.

Please note that these numbers often used in TON are far higher precision than native JavaScript numbers, and can cause unpredictable behavior if not anticipated. For this reason, we highly recommend using BN.js when manipulating values intended for the blockchain.

dataType (optional)

Type of data, awalible foramtras: hex, base64, boc and undefined If the field is undefined the data processed as a string.

data (optional)

Additional data (comment)