Split

Create a split transaction

Similar to the transfer function, this particular function generates a hexadecimal representation of a transaction that can distribute tokens to multiple addresses at once. It should be noted that this function is only applicable to tokens that have the splittable property set to true. For more details on which token templates possess this attribute, please refer to the STAS features table.

To create a split transaction, we need a STAS UTXO, a fee UTXO, and the private keys linked with these UTXOs. Instead of the destination address required in the transfer function, we need an array that contains all the destination addresses and their corresponding amounts.

The splitDestinations array is made up of objects that contain two fields. Please keep in mind that the sum of the outputs' amounts must match the amount in the STAS UTXO input to ensure a valid transaction is created.

const splitDestinations = [
    {
        satoshis : 10,
        address : "someAddressString"
    },
    {
        satoshis : 10,
        address : "someOtherAddressString"
    }
]

If the token owner needs to receive change from the STAS UTXO input, it must be included in the splitDestination array. The total amount in the outputs of the array should match the input satoshis amount.

const splitHex = await stasSplit.signed(
    ownerPrivatekey, 
    stasUtxo, 
    splitDestinations, 
    paymentUtxo, 
    paymentPrivateKey
)

After executing the function, you will receive a transaction hexadecimal representation that is now ready to be broadcasted to the miner.

Last updated