Multi-Signature Example Process Flow

Developers can effortlessly initiate multi-signature transactions using SDKs. This article will utilize the account PTBHseaG95LN7uMzbAVPeSAivGjw3iTeew as an illustration to employ Pollux web SDK for constructing a multi-signature transfer transaction on the YUVi 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

Modify Account Permission

Update the account permission through POXscan or by utilizing the wallet's accountpermissionupdate API. In this instance, an additional active permission titled "NewAddedActivePermission" is introduced to the account PTBHseaG95LN7uMzbAVPeSAivGjw3iTeew via Poxscan.

2. Query Account Permission

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

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

Returns:

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

In the obtained outcome, it is evident that the account PTBHseaG95LN7uMzbAVPeSAivGjw3iTeew possesses an Active authorization identified by the ID 3. The threshold for this authorization is 2, and it holds authority over two accounts, each assigned a weight of 1.

3. Select Permission and Create Transaction

In this instance, we opt for the active permission associated with ID 3 of PTBHseaG95LN7uMzbAVPeSAivGjw3iTeew to compose a multi-signature POX transfer transaction through the PolluxWeb.transactionBuilder.sendPox method.

var unsignedTransaction = await poxWeb.transactionBuilder.sendpox('PVqTEPUPiTxhzaSnD9xXEvarUQooLibkXM', 10000000, 'PTBHseaG95LN7uMzbAVPeSAivGjw3iTeew',{permissionId: 3});

Sender: the owner_address in the transaction, that is PTBHseaG95LN7uMzbAVPeSAivGjw3iTeew. When constructing a transaction, there's no need to concern yourself with the transaction creator; simply designate the sender of the POX in the transaction to the multi-signature address. Multi-signature permission: Opt for the active permission identified as 3 for PTBHseaG95LN7uMzbAVPeSAivGjw3iTeew - {permissionId: 3}.

4. Perform the Multi-Signing

The Active permission of PTBHseaG95LN7uMzbAVPeSAivGjw3iTeew with id 3 is authorized to "PW5Kzigm3yoKR2h2RWLSFLFeWZjL5SjHxg" and "PUTRPJVWcfKwpF3uxxdLPfrzBNENFC3Ruh". These two accounts can use PolluxWeb.pox.multiSign API to sign the transaction.

var signedTransaction = await poxWeb.pox.multiSign(unsignedTransaction, 'f0bd085afbcf31374cf6ae4585faee1366f8c850c596e2649ba93015ac479f74');

signedTransaction = await poxnWeb.pox.multiSign(signedTransaction, '6c72f51dc78d24ce1517912526a8a0e73379694ae7594efd3e05adb33d726edc');

Returns

```json
{
  "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"
  ]
}
```

Note: I left the `[Object]` as is, assuming it represents a nested object. Please replace it with the actual content if you have it.

5. Check Transaction's Sign Weight

Through the polluxweb.POX.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 poxWeb.POX.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"
    }
  }
}


Last updated