> For the complete documentation index, see [llms.txt](https://docs.swanchain.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.swanchain.io/bulders/tools/swan-sdk/go-swan-sdk/a-sample-tutorial.md).

# A Sample Tutorial

**New client**

```go
client, err := swan.NewAPIClient("<SWAN_API_KEY>")
```

**Fetch all instance resources**

Through `InstanceResources` you can get a list of available instance resources including their region information. You can select one you want to use.

```go
instances, err := swan.InstanceResources(true)
```

> **Note:** All Instance type list can be found [here](https://github.com/swanchain/go-swan-sdk/blob/main/doc/instance.md).

**Create and deploy a task**

Deploy a application, if you have set `PrivateKey`, this task will be payed automaiclly, and deploy to computing providers on Swan Chain Network:

```go
task, err := client.CreateTask(&CreateTaskReq{
    PrivateKey:   "<YOUR_WALLET_ADDRESS_PRIVATE_KEY>",
    RepoUri:      "<YOUR_PROJECT_GITHUB_URL>",
    Duration:      2 * time.Hour,
    InstanceType: "C1ae.small", 
})

taskUUID := task.Task.UUID
log.Printf("taskUUID: %v", taskUUID)

```

**Access application instances of an existing task**

You can easily get the deployed application instances for an existing task.

```go
// Get application instances URL
appUrls, err := client.GetRealUrl("<TASK_UUID>")
if err != nil {
	log.Fatalln(err)
}
log.Printf("app urls: %v", appUrls)
```

A sample output:

```
['https://krfswstf2g.anlu.loveismoney.fun', 'https://l2s5o476wf.cp162.bmysec.xyz', 'https://e2uw19k9uq.cp5.node.study']
```

It shows that this task has three applications. Visit the URL in the web browser you will view the application's information if it is running correctly.

**Renew duration of an existing task**

`RenewTask` extends the duration of the task before completed

```go
resp, err := client.RenewTask("<TASK_UUID>", <Duration>,"<PRIVATE_KEY>")
```

**Terminate an existing task**

You can early terminate an existing task and its application instances. By terminating task, you will stop all the related running application instances and thus you will get refund of the remaining task duration.

```go
resp, err := client.TerminateTask("<TASK_UUID>")
```

**Check information of an existing task**

You can get the task details by the `taskUUID`

```go
resp, err := client.TaskInfo("<TASK_UUID>")
```

**Check all task list information belonging to a wallet address**

You can get all tasks deployed from one wallet address

```go
total, resp, err := client.Tasks(&TaskQueryReq{
    Wallet: "<WALLET_ADDRESS>",
    Page:   0,
    Size:   10,
})
```

### More Samples

For more pratical samples, consult [go-swan-sdk-samples](https://github.com/swanchain/go-swan-sdk-samples).

### More Resources

More resources about swan SDK can be found

* [Swan Console platform](https://console.swanchain.io)
* [Deploying with Swan SDK](https://docs.swanchain.io/start-here/readme/deploying-with-swan-sdk)
* [Python-swan-sdk](https://github.com/swanchain/python-swan-sdk)
* [Python-swan-sdk-samples](https://github.com/swanchain/python-swan-sdk)

### License

The `go-swan-sdk` is released under the **MIT** license, details of which can be found in the LICENSE file.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.swanchain.io/bulders/tools/swan-sdk/go-swan-sdk/a-sample-tutorial.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
