Interact with multisig wallets using TypeScript
Introduction
If you don't know what is multisig wallet in TON, you can check it out here
Following this steps you will learn how to:
- Create and deploy multisig wallet
- Create, sign and send transactions with that wallet
We will create a TypeScript project and use ton library, so you need to install it first. We will also use the ton-access:
yarn add typescript @types/node ton ton-crypto ton-core buffer @orbs-network/ton-access
yarn tsc --init -t es2022
The full code of this guide is available here:
Create and deploy multisig wallet
Let's create a source file, main.ts
for example. Open it in your favorite code editor and follow this guide!
At first we need to import all important stuff
import { Address, beginCell, MessageRelaxed, toNano, TonClient, WalletContractV4, MultisigWallet, MultisigOrder, MultisigOrderBuilder } from "ton";
import { KeyPair, mnemonicToPrivateKey } from 'ton-crypto';
import { getHttpEndpoint } from "@orbs-network/ton-access";
Create TonClient
instance:
const endpoint = await getHttpEndpoint();
const client = new TonClient({ endpoint });
Than we need keypairs to work with:
let keyPairs: KeyPair[] = [];
let mnemonics[] = [
['orbit', 'feature', ...], //this should be the seed phrase of 24 words
['sing', 'pattern', ...],
['piece', 'deputy', ...],
['toss', 'shadow', ...],
['guard', 'nurse', ...]
];
for (let i = 0; i < mnemonics.length; i++) keyPairs[i] = await mnemonicToPrivateKey(mnemonics[i]);
There are two ways to create MultisigWallet
object:
- Import existing one from address
let addr: Address = Address.parse('EQADBXugwmn4YvWsQizHdWGgfCTN_s3qFP0Ae0pzkU-jwzoE');
let mw: MultisigWallet = await MultisigWallet.fromAddress(addr, { client });
- Create a new one
let mw: MultisigWallet = new MultisigWallet([keyPairs[0].publicKey, keyPairs[1].publicKey], 0, 0, 1, { client });