# unsafe_payAllSui

> For the complete documentation index, see [llms.txt](/docs/llms.txt).

POST https://sui-mainnet.g.alchemy.com/v2/{apiKey}

Creates an unsigned transaction that transfers all SUI coins to one recipient.  All SUI from the input coins are consolidated into the first coin, which is  then transferred and used as the gas object. Remaining input coins are deleted.


Reference: https://www.alchemy.com/docs/chains/sui/sui-api-endpoints/unsafe-pay-all-sui

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| signer | string | Yes | The transaction signer's Sui address. |
| input_coins | string[] | Yes | List of Coin&lt;SUI&gt; object IDs to use, including the one used for gas. |
| recipient | string | Yes | The recipient's Sui address. |
| gas_budget | string | Yes | The gas budget for the transaction. |

## Result

**result** (object): Unsigned transaction that transfers all SUI.

## Example

### Request

```json
{
  "jsonrpc": "2.0",
  "method": "unsafe_payAllSui",
  "params": [
    "0x00c364252964511b32b084c17a492093d5b762cbe2766d46911912718e56950f",
    [
      "0xee65df446c896504512cb35a83f82510c10fd2fab5de2b51a3a63ff6f7106da7"
    ],
    "0xeeb30f4dc675a7d49b8abedf58eb2e3738facfc554c80f4b27ab62aa02878f56",
    "2000"
  ],
  "id": 1
}
```

### Response

```json
{
  "jsonrpc": "2.0",
  "result": {
    "txBytes": "AAABACDusw9NxnWn1JuKvt9Y6y43OPrPxVTID0snq2KqAoePVgEBAQABAAAAw2QlK...",
    "gas": [
      {
        "objectId": "0xee65df446c896504512cb35a83f82510c10fd2fab5de2b51a3a63ff6f7106da7",
        "version": 1,
        "digest": "jKbAsTuqaK9k6hb27Z5xxnQVmTSWoU6dkL82x44c2dW"
      }
    ],
    "inputObjects": [
      {
        "ImmOrOwnedMoveObject": {
          "objectId": "0xee65df446c896504512cb35a83f82510c10fd2fab5de2b51a3a63ff6f7106da7",
          "version": 1,
          "digest": "jKbAsTuqaK9k6hb27Z5xxnQVmTSWoU6dkL82x44c2dW"
        }
      }
    ]
  },
  "id": 1
}
```

## Code Examples

### cURL

```bash
curl --request POST \
  --url https://sui-mainnet.g.alchemy.com/v2/docs-demo \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "unsafe_payAllSui",
  "params": [
    "0x00c364252964511b32b084c17a492093d5b762cbe2766d46911912718e56950f",
    [
      "0xee65df446c896504512cb35a83f82510c10fd2fab5de2b51a3a63ff6f7106da7"
    ],
    "0xeeb30f4dc675a7d49b8abedf58eb2e3738facfc554c80f4b27ab62aa02878f56",
    "2000"
  ]
}'
```

### JavaScript

```javascript
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'unsafe_payAllSui',
    params: [
      '0x00c364252964511b32b084c17a492093d5b762cbe2766d46911912718e56950f',
      ['0xee65df446c896504512cb35a83f82510c10fd2fab5de2b51a3a63ff6f7106da7'],
      '0xeeb30f4dc675a7d49b8abedf58eb2e3738facfc554c80f4b27ab62aa02878f56',
      '2000'
    ]
  })
};

fetch('https://sui-mainnet.g.alchemy.com/v2/docs-demo', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://sui-mainnet.g.alchemy.com/v2/docs-demo"

payload = {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "unsafe_payAllSui",
    "params": ["0x00c364252964511b32b084c17a492093d5b762cbe2766d46911912718e56950f", ["0xee65df446c896504512cb35a83f82510c10fd2fab5de2b51a3a63ff6f7106da7"], "0xeeb30f4dc675a7d49b8abedf58eb2e3738facfc554c80f4b27ab62aa02878f56", "2000"]
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

### Go

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://sui-mainnet.g.alchemy.com/v2/docs-demo"

	payload := strings.NewReader("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"unsafe_payAllSui\",\n  \"params\": [\n    \"0x00c364252964511b32b084c17a492093d5b762cbe2766d46911912718e56950f\",\n    [\n      \"0xee65df446c896504512cb35a83f82510c10fd2fab5de2b51a3a63ff6f7106da7\"\n    ],\n    \"0xeeb30f4dc675a7d49b8abedf58eb2e3738facfc554c80f4b27ab62aa02878f56\",\n    \"2000\"\n  ]\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(string(body))

}
```

### Java

```java
HttpResponse<String> response = Unirest.post("https://sui-mainnet.g.alchemy.com/v2/docs-demo")
  .header("Content-Type", "application/json")
  .body("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"unsafe_payAllSui\",\n  \"params\": [\n    \"0x00c364252964511b32b084c17a492093d5b762cbe2766d46911912718e56950f\",\n    [\n      \"0xee65df446c896504512cb35a83f82510c10fd2fab5de2b51a3a63ff6f7106da7\"\n    ],\n    \"0xeeb30f4dc675a7d49b8abedf58eb2e3738facfc554c80f4b27ab62aa02878f56\",\n    \"2000\"\n  ]\n}")
  .asString();
```

### C#

```csharp
using RestSharp;


var options = new RestClientOptions("https://sui-mainnet.g.alchemy.com/v2/docs-demo");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddJsonBody("{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 1,\n  \"method\": \"unsafe_payAllSui\",\n  \"params\": [\n    \"0x00c364252964511b32b084c17a492093d5b762cbe2766d46911912718e56950f\",\n    [\n      \"0xee65df446c896504512cb35a83f82510c10fd2fab5de2b51a3a63ff6f7106da7\"\n    ],\n    \"0xeeb30f4dc675a7d49b8abedf58eb2e3738facfc554c80f4b27ab62aa02878f56\",\n    \"2000\"\n  ]\n}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content);

```


## OpenRPC Method Specification

```yaml
name: unsafe_payAllSui
summary: Transfer all SUI coins to a single recipient
description: |
  Creates an unsigned transaction that transfers all SUI coins to one recipient.  All SUI from the input coins are consolidated into the first coin, which is  then transferred and used as the gas object. Remaining input coins are deleted.
params:
  - name: signer
    required: true
    description: The transaction signer's Sui address.
    schema:
      type: string
  - name: input_coins
    required: true
    description: List of Coin&lt;SUI&gt; object IDs to use, including the one used for gas.
    schema:
      type: array
      items:
        type: string
  - name: recipient
    required: true
    description: The recipient's Sui address.
    schema:
      type: string
  - name: gas_budget
    required: true
    description: The gas budget for the transaction.
    schema:
      type: string
result:
  name: result
  description: Unsigned transaction that transfers all SUI.
  schema:
    type: object
    properties:
      txBytes:
        type: string
        description: Base64-encoded BCS serialized transaction bytes.
      gas:
        type: array
        description: Gas object(s) selected for the transaction.
        items:
          type: object
          properties:
            objectId:
              type: string
            version:
              type: integer
            digest:
              type: string
      inputObjects:
        type: array
        description: All objects involved in this transaction (SUI coins).
        items:
          type: object
examples:
  - name: Send all SUI to one recipient
    params:
      - name: signer
        value: '0x00c364252964511b32b084c17a492093d5b762cbe2766d46911912718e56950f'
      - name: input_coins
        value:
          - '0xee65df446c896504512cb35a83f82510c10fd2fab5de2b51a3a63ff6f7106da7'
      - name: recipient
        value: '0xeeb30f4dc675a7d49b8abedf58eb2e3738facfc554c80f4b27ab62aa02878f56'
      - name: gas_budget
        value: '2000'
    result:
      name: result
      value:
        txBytes: AAABACDusw9NxnWn1JuKvt9Y6y43OPrPxVTID0snq2KqAoePVgEBAQABAAAAw2QlK...
        gas:
          - objectId: '0xee65df446c896504512cb35a83f82510c10fd2fab5de2b51a3a63ff6f7106da7'
            version: 1
            digest: jKbAsTuqaK9k6hb27Z5xxnQVmTSWoU6dkL82x44c2dW
        inputObjects:
          - ImmOrOwnedMoveObject:
              objectId: '0xee65df446c896504512cb35a83f82510c10fd2fab5de2b51a3a63ff6f7106da7'
              version: 1
              digest: jKbAsTuqaK9k6hb27Z5xxnQVmTSWoU6dkL82x44c2dW
```
