Overview
This tutorial helps you learn how to deploy your multisig contract. Recall that a -multisig contract is a multi-signature wallet with private key holders, which accepts requests to send messages if the request (a.k.a. order, query) collects at least holder’s signatures. Based on the original multisig contract code and updates by akifoq:- Original TON Blockchain multisig-code.fc
- akifoq/multisig with Fift libraries to work with multisig.
Prefer videos over text?Watch this if you are new to multi-signature wallets: What is Multisig Technology? (video)
What you’ll learn
- How to create and customize a simple multisig wallet.
- How to deploy a multisig wallet using Lite client.
- How to sign a request and send it in a message to the blockchain.
Set up your environment
Before we begin our journey, check and prepare your environment.- Install
func
,fift
,lite-client
binaries, andfiftlib
from the latest GitHub release. - Clone the repository and open its directory in CLI.
Get started
- Compile the code to Fift.
- Prepare multisig owner’s keys.
- Deploy your contract.
- Interact with the deployed multisig wallet in the blockchain.
Compile the contract
Compile the contract to Fift with:Prepare multisig owner’s keys
Create participant’s keys
To create a key, you need to run:- Where
KEY_NAME
is the file name where the private key will be written.
multisig_key.pk
file with the private key inside.
Collect public keys
Also, the script will issue a public key in the format:Public key =
needs to be saved somewhere!
Let’s store it in a file called keys.txt
. It’s important to have one public key per line.
Deploy your contract
Deploy via lite-client
After creating all the keys, you need to collect the public keys into a text file, keys.txt
.
For example:
$WALLET_ID$
: the wallet number assigned to the current key. It is recommended that each new wallet with the same key use a unique$WALLET_ID$
.$KEYS_COUNT$
: the number of keys needed for confirmation, usually equal to the number of public keys.
Wallet ID explainedIt is possible to create many wallets with the same keys (Alice key, Bob key). What should we do if Alice and Bob already share a wallet? That’s why
$WALLET_ID$
is crucial here.If you have a “public key must be 48 characters long” error, please make sure your
keys.txt
uses Unix-style line endings (LF). For example, line endings can be changed via Sublime Text.Activate your contract
You need to send some TON to the newly generated wallet. For example, 0.5 TON. You can send testnet coins via @testgiver_ton_bot. After that, runlite-client
:
After starting Lite client, it’s best to run the
time
command in the lite-client
console to make sure the connection was successful:
Interact with a multisig wallet
Create a request
First, you need to create a message request:$ADDRESS$
- address where to send coins.$AMOUNT$
- number of coins (in TON).$MESSAGE$
- the file name for the compiled message.
Use the
-C comment
attribute to add a comment for your transaction. To get more information, run the create-msg.fif file without parameters.Choose a wallet
Next, you need to choose a wallet to send coins from:$WALLET_ID$
— ID of the wallet backed by this multisig contract.$AWAIT_TIME$
— time in seconds the smart contract will await signatures from the multisig wallet owners for the request.$MESSAGE$
— name of the message BoC file created in the previous step.
The request expires if
$AWAIT_TIME$
elapses before the request is signed. As usual, $AWAIT_TIME$
equals a couple of hours (7200 seconds).order.boc
.
order.boc
must be shared with key holders; they must sign it.Sign your part
To sign, run:$KEY$
- file name containing the private key to sign, without extension.$KEY_INDEX$
- index of the given key inkeys.txt
(zero-based).
multisig_key.pk
file:
Create a message
After everyone has signed the order, it needs to be turned into a message for the wallet and signed again with the following command:Send the signed message to the TON blockchain
After that, startlite-client
again: