@okxweb3/coin-ton
v1.0.9
Published
TON SDK is used to interact with the TON/Venom blockchain, it contains various functions can be used to web3 wallet.
Downloads
370
Keywords
Readme
@okxweb3/coin-ton
TON SDK is used to interact with the TON/Venom blockchain, it contains various functions can be used to web3 wallet.
Installation
Npm
To obtain the latest version, simply require the project using npm :
npm install @okxweb3/coin-ton
Usage
TON
Generate address
import { TonWallet } from "@okxweb3/coin-ton";
const wallet = new TonWallet();
const param = {
privateKey: "fc81e6f42150458f53d8c42551a8ab91978a55d0e22b1fd890b85139086b93f8"
};
const address = await wallet.getNewAddress(param);
Verify address
import { TonWallet } from "@okxweb3/coin-ton";
const wallet = new TonWallet();
const param = {
address: "EQA3_JIJKDC0qauDUEQe2KjQj1iLwQRtrEREzmfDxbCKw9Kr"
};
const isValid = await wallet.validAddress(param);
Transfer TON
import { TonWallet } from "@okxweb3/coin-ton";
const wallet = new TonWallet();
const param = {
privateKey: "fc81e6f42150458f53d8c42551a8ab91978a55d0e22b1fd890b85139086b93f8",
data: {
to: "EQA3_JIJKDC0qauDUEQe2KjQj1iLwQRtrEREzmfDxbCKw9Kr",
amount: "10000000",
seqno: 2,
toIsInit: true,
memo: "",
},
};
const tx = await wallet.signTransaction(param);
parameters
to
, address, TON token接收地址amount
, number, TON转账的数量,TON精度是9seqno
, number, nonce or sequence of from address,toIsInit
, boolean, destination address init or notmemo
, string, comment for this txexpireAt
, number, timeout at seconds eg, 1718863283n, default now + 60ssendMode
, SendMode, 用于控制交易的行为和模式,决定了消息(通常是转账交易)的处理方式,不同的mode可以组合使用,有以下取值- CARRY_ALL_REMAINING_BALANCE = 128, 用于指示将账户的所有剩余余额发送出去。这在某些情况下非常有用,比如清空账户余额时。
- CARRY_ALL_REMAINING_INCOMING_VALUE = 64, 用于指示所有剩余的传入价值(比如剩余的资金)应该被携带并发送出去,而不是留下来。
- DESTROY_ACCOUNT_IF_ZERO = 32,它确保在交易完成后,如果目标账户的余额为零,则销毁该账户。这种方式可以用于自动清理不再需要的账户,从而减少存储使用
- 16, 在动作失败的情况下 - 弹回交易。如果使用+2,则无效。
- PAY_GAS_SEPARATELY = 1, 用于指示消息的 gas 费用应该从发送者账户中单独支付,而不是从消息附带的金额中扣除。
- IGNORE_ERRORS = 2, 当启用此标志时,即使在处理消息时发生错误,也会继续处理该消息,而不会将错误传播给调用者。这在某些情况下非常有用,例如在发送非关键性消息或进行非重要操作时,你希望保证消息的发送而不关心处理中的错误。
- NONE = 0 ,在转账的时候,如果目标账户没有足够的余额支付传输费用,消息会失败
Venom
Generate address
import { VenomWallet } from "@okxweb3/coin-ton";
const wallet = new VenomWallet();
const param = {
privateKey: "fc81e6f42150458f53d8c42551a8ab91978a55d0e22b1fd890b85139086b93f8"
};
const address = await wallet.getNewAddress(param);
Verify address
import { VenomWallet } from "@okxweb3/coin-ton";
const wallet = new VenomWallet();
const param = {
address: "0:6bef7d76e46fd1f308f0bf0b59f1ca6318aa6d950ea00aecc7d162218acaaa36"
};
const isValid = await wallet.validAddress(param);
Transfer Venom
import { VenomWallet } from "@okxweb3/coin-ton";
const wallet = new VenomWallet();
const param = {
privateKey: "fc81e6f42150458f53d8c42551a8ab91978a55d0e22b1fd890b85139086b93f8",
data: {
to: "0:6bef7d76e46fd1f308f0bf0b59f1ca6318aa6d950ea00aecc7d162218acaaa36",
amount: "10000000",
seqno: 2,
toIsInit: true,
memo: "",
globalId: 1000,
},
};
const tx = await wallet.signTransaction(param);
License
Most packages or folder are MIT licensed, see package or folder for the respective license.