HomeGuidesAPI ReferenceChangelog
GuidesAPI ReferenceCommunityDiscordBlogFAQBug BountyAnnouncementsChange Log
Guides

Multi-Signature Example Process Flow

Developers can easily send multi-signature transactions using SDKs. This article will use the account TUZKijZ9Esy8JEkrqMpaVgtbDKKNA5p5CZ as an example to use tronweb SDK to build a multi-signature transfer transaciton on the Nile test network.

The steps for multi-signature transaction are as follows::

  1. Modify account permission
  2. Query account permission
  3. Select permission and create transaction
  4. Perform the multi-signing
  5. Check transaction's sign weight
  6. Check approved list
  7. Broadcast transaction

1. Modify Account Permission

Modify account permission through tronscan or using the wallet/accountpermissionupdate API. In this example, a new active permission named "NewAddedActivePermission" is added to the account TUZKijZ9Esy8JEkrqMpaVgtbDKKNA5p5CZ through tronscan.

2. Query Account Permission

Use the wallet/getaccount API to query account permission information:

curl --location --request POST 'https://api.nileex.io/wallet/getaccount' \
--header 'Content-Type: text/plain' \
--data-raw '{
     "address": "TUZKijZ9Esy8JEkrqMpaVgtbDKKNA5p5CZ",
     "visible": true
}'

Returns:

{
    "address": "TUZKijZ9Esy8JEkrqMpaVgtbDKKNA5p5CZ",
    "balance": 2897800000,
    ......
    "owner_permission": {
        "permission_name": "owner",
        "threshold": 1,
        "keys": [
            {
                "address": "TUZKijZ9Esy8JEkrqMpaVgtbDKKNA5p5CZ",
                "weight": 1
            }
        ]
    },
    "active_permission": [
        {
            "type": "Active",
            "id": 2,
            "permission_name": "active",
            "threshold": 1,
            "operations": "7fff1fc0033efb0f000000000000000000000000000000000000000000000000",
            "keys": [
                {
                    "address": "TUZKijZ9Esy8JEkrqMpaVgtbDKKNA5p5CZ",
                    "weight": 1
                }
            ]
        },
        {
            "type": "Active",
            "id": 3,
            "permission_name": "NewAddedActivePermission",
            "threshold": 2,
            "operations": "77ff07c00260c30f000000000000000000000000000000000000000000000000",
            "keys": [
                {
                    "address": "TXTMqofe9nS5bN5tfhfd6ayWocJm7oxJKT",
                    "weight": 1
                },
                {
                    "address": "TVqTEPUPiTxhzaSnD9xXEvarUQooLibkXM",
                    "weight": 1
                }
            ]
        }
    ],
    ......
}

From the returned result, we can see that the account TUZKijZ9Esy8JEkrqMpaVgtbDKKNA5p5CZ has an Active permission with id 3, its threshold is 2, and it is authorized to two accounts, and the weight of each account is 1.

3. Select Permission and Create Transaction

In this example, we choose to use the active permission with id 3 of TUZKijZ9Esy8JEkrqMpaVgtbDKKNA5p5CZ to construct a multi-signature TRX transfer transaction through the tronWeb.transactionBuilder.sendTrx method:

var unsignedTransaction = await tronWeb.transactionBuilder.sendTrx('TVqTEPUPiTxhzaSnD9xXEvarUQooLibkXM', 10000000, 'TUZKijZ9Esy8JEkrqMpaVgtbDKKNA5p5CZ',{permissionId: 3});
  • Sender: the owner_address in the transaction, that is TUZKijZ9Esy8JEkrqMpaVgtbDKKNA5p5CZ. When building a transaction, you don't need to care about the transaction creator, just set the sender of the TRX in the transaction to the multi-signature address.
  • Multi-signature permission: Select the active permission with id 3 of TUZKijZ9Esy8JEkrqMpaVgtbDKKNA5p5CZ - {permissionId: 3}

4. Perform the Multi-Signing

The Active permission of TUZKijZ9Esy8JEkrqMpaVgtbDKKNA5p5CZ with id 3 is authorized to "TXTMqofe9nS5bN5tfhfd6ayWocJm7oxJKT" and "TVqTEPUPiTxhzaSnD9xXEvarUQooLibkXM". These two accounts can use tronWeb.trx.multiSign API to sign the transaction:

var signedTransaction = await tronWeb.trx.multiSign(unsignedTransaction, 'f0bd085afbcf31374cf6ae4585faee1366f8c850c596e2649ba93015ac479f74');

signedTransaction = await tronWeb.trx.multiSign(signedTransaction, '6c72f51dc78d24ce1517912526a8a0e73379694ae7594efd3e05adb33d726edc');

Returns:

{
  visible: false,
  txID: '507efa43ef267005cd384f74f8bc2b2d6e807807144144fd01f194f36ddfb93a',
  raw_data: {
    contract: [ [Object] ],
    ref_block_bytes: 'e5b2',
    ref_block_hash: 'c565570704ef1e7a',
    expiration: 1700538150000,
    timestamp: 1700538091138
  },
  raw_data_hex: '0a02e5b22208c565570704ef1e7a40f0d8e3ffbe315a6a080112640a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412330a1541cbe603e1f0ac26c50bb795d8d54a95706c64b2e2121541d9eb1101ba37f55c436cc668ed1ac18d23d6c6631880ade204280370828de0ffbe31',
  signature: [
    '9f51d0839b8dd10b5a6bc3b043f6246d5c8a00a79839a52b0987ee337911b3375d0376c3b1aef3a7ffa0779a2e3d0cb95380294e6b934f738964a0551675d45501',
    '2bc656a647cbd9de932bf63909f73aacf2e97f0c771bd72b69654f6242a152e8ecbc8712ad59fe95a280cffbed5ef2dd28777dc27267976fe0c6374e00ba355c01'
  ]
}


5. Check Transaction's Sign Weight

Through the tronweb.trx.getSignWeight method, you can not only check the weight required by the permission, but also check how many addresses are currently signed and the current weight. It can be called during or after the multi-signature process.

var signWeight = await tronWeb.trx.getSignWeight(signedTransaction);

Returns:

{
  result: {},
  approved_list: [
    '41d9eb1101ba37f55c436cc668ed1ac18d23d6c663',
    '41ebadab040181bcc649169d00c28a3ad1bb6bfeb7'
  ],
  permission: {
    operations: '77ff07c00260c30f000000000000000000000000000000000000000000000000',
    keys: [ [Object], [Object] ],
    threshold: 2,
    id: 3,
    type: 'Active',
    permission_name: 'NewAddedActivePermission'
  },
  current_weight: 2,
  transaction: {
    result: { result: true },
    txid: '507efa43ef267005cd384f74f8bc2b2d6e807807144144fd01f194f36ddfb93a',
    transaction: {
      signature: [Array],
      txID: '507efa43ef267005cd384f74f8bc2b2d6e807807144144fd01f194f36ddfb93a',
      raw_data: [Object],
      raw_data_hex: '0a02e5b22208c565570704ef1e7a40f0d8e3ffbe315a6a080112640a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412330a1541cbe603e1f0ac26c50bb795d8d54a95706c64b2e2121541d9eb1101ba37f55c436cc668ed1ac18d23d6c6631880ade204280370828de0ffbe31'
    }
  }
}


6. Check Approved List

You can also view the list of accounts that have signed the transaction through tronWeb.trx.getApprovedList.

var approvedList = await tronWeb.trx.getApprovedList(signedTransaction);

Returns:

{
  result: {},
  approved_list: [
    '41d9eb1101ba37f55c436cc668ed1ac18d23d6c663',
    '41ebadab040181bcc649169d00c28a3ad1bb6bfeb7'
  ],
  transaction: {
    result: { result: true },
    txid: '507efa43ef267005cd384f74f8bc2b2d6e807807144144fd01f194f36ddfb93a',
    transaction: {
      signature: [Array],
      txID: '507efa43ef267005cd384f74f8bc2b2d6e807807144144fd01f194f36ddfb93a',
      raw_data: [Object],
      raw_data_hex: '0a02e5b22208c565570704ef1e7a40f0d8e3ffbe315a6a080112640a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412330a1541cbe603e1f0ac26c50bb795d8d54a95706c64b2e2121541d9eb1101ba37f55c436cc668ed1ac18d23d6c6631880ade204280370828de0ffbe31'
    }
  }
}

7. Broadcast Transaction

Once multi-signing completes, you can broadcast the signed transaction directly and check the transaction by using getTransactionById later.

var result = await tronWeb.trx.broadcast(signedTransaction);

Returns:

{
  result: true,
  txid: '507efa43ef267005cd384f74f8bc2b2d6e807807144144fd01f194f36ddfb93a',
  transaction: {
    visible: false,
    txID: '507efa43ef267005cd384f74f8bc2b2d6e807807144144fd01f194f36ddfb93a',
    raw_data: {
      contract: [Array],
      ref_block_bytes: 'e5b2',
      ref_block_hash: 'c565570704ef1e7a',
      expiration: 1700538150000,
      timestamp: 1700538091138
    },
    raw_data_hex: '0a02e5b22208c565570704ef1e7a40f0d8e3ffbe315a6a080112640a2d747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e5472616e73666572436f6e747261637412330a1541cbe603e1f0ac26c50bb795d8d54a95706c64b2e2121541d9eb1101ba37f55c436cc668ed1ac18d23d6c6631880ade204280370828de0ffbe31',
    signature: [
      '9f51d0839b8dd10b5a6bc3b043f6246d5c8a00a79839a52b0987ee337911b3375d0376c3b1aef3a7ffa0779a2e3d0cb95380294e6b934f738964a0551675d45501',
      '2bc656a647cbd9de932bf63909f73aacf2e97f0c771bd72b69654f6242a152e8ecbc8712ad59fe95a280cffbed5ef2dd28777dc27267976fe0c6374e00ba355c01'
    ]
  }
}