Swan Chain
  • BULDERS
    • Getting Started
    • DApp Developer
      • Deploying Your First Smart Contract with Remix
      • Interacting with Smart Contract on Swan Chain Using Go
    • App Developer
      • Building Docker Images and Deployment file with LDL
        • Lagrange Definition Language(LDL)
      • Deploying with Swan SDK
      • Store and Retrieve a File with Swan Storage
        • 1. Set up the python-MCS-SDK
        • 2.Create and Manage Buckets
        • 3.Upload Files and Folders
        • 4.Retrieve and Download Files
        • 5.Delete Files and Buckets
    • Node Operator
      • Swan Node Snapshots
    • Market Provider
      • Storage Market
      • AI/ML Orchestrator
        • Decentralized AI Marketplace
        • Connect to Orchestrator
      • Web3 ZK Computing Market
        • ZK Auction Engine
        • Sequencer
        • Contribute zk-UBI-task
          • How to Contribute
        • Example
      • Customized Market Provider
    • Computing Provider
      • Fog Computing Provider(FCP)
        • FCP Setup
        • Migrating FCP to Swan Mainnet
        • FCP Funding Operations Guide
        • FCP FAQ
      • Edge Computing Provider (ECP)
        • ECP Setup
        • ECP Funding Operations Guide
        • ECP FAQ
      • FAQ
    • Storage Provider
      • Storage Auction System
    • Developer Tools
      • Swan SDK
        • Python Swan SDK
          • Special Case: Create ssh login instance
          • SWAN Orchestrator SDK - Function and Parameter Reference
        • Go Swan SDK
          • A Sample Tutorial
      • Swan Console
        • Getting Started
        • Blockchain GPU Task Example
        • Custom Blockchain GPU Task Pools
      • Lagrange
      • Swan IPFS Storage
      • Nebula Block Cloud
      • Ecosystem Projects
    • Mission 3.0
      • Get Started
        • For Users
        • For Space Holders
  • NETWORK REFERENCE
    • Network Info
      • Set Up Your Wallet
      • Bridge Token
    • Contract Addresses
    • Fees
  • Core Concepts
    • Introduction to Swan Chain
    • Consensus Layer
    • Peer-to-peer (P2P) Network
    • Payment Channels
    • Service Discovery
    • Market Provider
      • Storage Market
      • AI Computing Marketplace
        • Orchestrator
        • Auction Engine
        • Bidding Task State Machine
      • ZK Proof Marketplace
        • ZK Task
        • ZK Pool
    • Storage Layer
    • Computing Layer
      • Computing Provider Protocol
      • Computing Provider Account
      • Layer3 Computing Protocol
      • Reputation System
      • Dynamic Pricing
    • CDN Layer
    • Tokenomics
      • UBI Allocation Curve
      • Computing Provider Income
      • Computing Provider Collateral
        • Collateral Requirement and Computing Unit
        • DePIN Oracle
      • Governance
        • Treasure DAO
    • Glossary
  • Swan Chain Campaign
    • Swan CP UBI
    • Swan Chain Mainnet
      • Network Information
      • Swan Token
      • Swan Chain Mission
        • Social Mission
        • Onchain Mission
        • Mission: Celestial Bloom
      • Swan Provider Campaign
        • Fog Computing Provider (FCP)
        • Edge Computing Provider (ECP)
        • Market Provider (MP)
      • GALXE Campaign
      • Free Tier and Special Credit Programs
    • Atom Accelerator Race
      • Before You Get Started
        • Set Up MetaMask
        • Claim SepoliaETH
        • Claim testSWAN
      • CP Acceleration Program
      • Builder Acceleration Program
      • On-chain Interaction Race
      • Community Engagement Challenge
      • FAQ
    • Swan Saturn Testnet
      • Before You Get Started
        • Set Up MetaMask
        • Claim Faucet Tokens
        • Bridge Tokens
      • Transaction Drive Program
      • Community and Educational Events
      • Partnership and Integration Program
      • KOL Program
      • Computing Provider Program
        • FAQ
      • Developer Grant Program
      • FAQ
    • Swan Jupiter Testnet
      • How to Participate
      • Before You Get Started
      • Network Early Adopter
      • FAQ
  • RESOURCE
    • Links
    • Brand Kit
Powered by GitBook
On this page
  • More Samples
  • More Resources
  • License
  1. BULDERS
  2. Developer Tools
  3. Swan SDK
  4. Go Swan SDK

A Sample Tutorial

PreviousGo Swan SDKNextSwan Console

Last updated 8 months ago

New client

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.

instances, err := swan.InstanceResources(true)

Note: All Instance type list can be found .

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:

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.

// 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

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.

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

Check information of an existing task

You can get the task details by the taskUUID

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

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

More Samples

More Resources

More resources about swan SDK can be found

License

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

For more pratical samples, consult .

here
go-swan-sdk-samples
Swan Console platform
Deploying with Swan SDK
Python-swan-sdk
Python-swan-sdk-samples