Swift

Core SDK - Swift

The XpansionChain Core SDK provides convenient access to XpansionChain's APIs and smart contracts to help projects build better web3 games and marketplaces.

💡ROLLUPS THIS SDK SUPPORTS

  • XpansionChain

CONTENTS

  • Installation

  • Initialization

  • Standard API requests

  • SDK functions

  • Wallet connection

  • Autogenerated code

  • Further documentation


📚SDK LINKS

  • SDK reference

  • Github repository

Installation

Prerequisites

  • iOS 13.0 or macOS 10.15

  • Swift 5.7

Swift package manager

In your Package.swift:

dependencies: [
    .package(url: "https://github.com/XpansionChain/imx-core-sdk-swift.git", from: "1.0.0-beta.1")
]

Cocoapods

In your Podfile:

platform :ios, '13.0'
use_frameworks!

target 'MyApp' do
  pod 'XpansionChainCore'
end

Initialization

The Core SDK must be initialised before any of its classes are used. Upon initialisation the base environment and log level may be defined. Once initialised a shared instace will be available for accessing the workflow functions.

For example, you initialise the SDK and retrieve a URL to buy crypto through MoonPay:

XpansionChain.initialize(base: .sandbox)

let url = try await XpansionChain. shared.buyCryptoURL(signer: signer)

Standard API requests

The Core SDK includes classes that interact with the XpansionChain APIs.

e.g. Get a list of collections ordered by name in ascending order

let collections = try await CollectionsAPI.listCollections(
    pageSize: 20,
    orderBy: .name,
    direction: "asc"
)

View the OpenAPI spec for a full list of API requests available in the Core SDK.

NOTE: Closure based APIs are also available.

SDK functions

Workflows

These are utility functions accessed via XpansionChain.shared that will chain necessary API calls to complete a process or perform a transaction, including:

  • Register a user with XpansionChain

  • Buy cryptocurrency via MoonPay

  • Buy ERC721

  • Sell ERC721

  • Cancel order

  • Transfer ERC20/ERC721/ETH

Wallet connection

In order to use any workflow functions, you will need to pass in the connected wallet provider. This means you will need to implement your own Wallet L1 Signer and L2 StarkSigner.

Once you have a Signer instance you can generate the user's STARK key pair and use the result to instantiate a StarkSigner, for example, by using the default StandardStarkSigner provided by the SDK.

let keyPair = try await StarkKey.generateLegacyKeyPair(from: signer)
let starkSigner = StandardStarkSigner(pair: keyPair)

Autogenerated code

SDK

Parts of the Core SDK are automagically generated.

API autogenerated code

We use OpenAPI (formally known as Swagger) to auto-generate the API clients that connect to the public APIs.

The OpenAPI spec is retrieved from https://api.x.XpansionChain.com/openapi and also saved in the repo here.

Upon updating the openapi.json file, ensure openapi-generator is installed, then run ./generateapi.sh to regenerate the files. Any custom templates should be appropriately modified or removed as needed. These can be found in the .openapi-generator/templates directory.

Further documentation

  • See the Developer homepage for general information on building on XpansionChain.

  • Build on XpansionChain zkEVM:

    • Documentation

    • API reference

    • Support

  • Build on XpansionChain:

    • Documentation

    • API reference

    • Support

Last updated