How to use the sui_paySui method

The paySui method, along with payAllSui are special methods that do not require a gas Coin object. All other methods do require gas Object.

The paySui method accepts an array of coins the address owns, it merges them all into the first coin, this means the first coin in the array will remain (with the same id). This also introduces the necessity of making sure that the first coin in the array to have enough balance to cover the gas costs. Thus the first coin of the array should hold the largest balance, and at least equal to the gas-budget we desire, to make sure the call will not fail.

Next the method also requires two arrays of the same length. One array is called “amounts” and holds balance values. The second array is called “recipients” and it holds addresses. Remember that inputs should be strings, when having arrays as arguments, their elements should also be strings. Thus the “amounts” array should hold integers that were cast into strings.
The paySui will take the merged coin, will create new coins based on the values inside the “amounts” array and send those coins to the addresses in the “recipients” array. The correlation is one to one, meaning the first amount will go to the first recipient, the second amount to the second recipient, so on…
The remainder will be returned to our address.

This makes paySui handy in case we want to split a coin or coins into many desired coins. We fill the “amounts” array with the desired values and add repeatedly our address into the “recipients” array. We should add our address as many times as values we have in the “amounts” array.

We will send two coins of 5000 MIST to the same friend and a coin of 10000 MIST to ourselves with paySui. As inputs we will use coins of low value that we want merged and have no use for. This example will use the sui cli client and the command is sui client pay_sui.
The input coins are: 0x593c74d247e25b5d7dee4a0c54351fed85d4b842 , 0x9765d520a8d23b86fce17376385a3d1cdb41d745 and 0xd4030d23f6c9f8faa4b3d618974dca04d419301a.
Our friend’s address is 0x8b91cbc54215f3be3548dbabc2fa1a06259e8af7
Our address is 0xb38bb5d7e904c3acf6790149d50272c20fba529e


sui client pay_sui --input-coins 0x593c74d247e25b5d7dee4a0c54351fed85d4b842 0x9765d520a8d23b86fce17376385a3d1cdb41d745 0xd4030d23f6c9f8faa4b3d618974dca04d419301a \
--amounts 5000 5000 1000 \
--recipients 0x8b91cbc54215f3be3548dbabc2fa1a06259e8af7 0x8b91cbc54215f3be3548dbabc2fa1a06259e8af7 0xb38bb5d7e904c3acf6790149d50272c20fba529e \
--gas-budget 1000

The response we get confirms that we succeeded.
Make sure you make use of this handy method when you want to send a lot of coins to different addresses or you want to split your coins into many new ones.