Swiftpack.co - metaplex-foundation/solita-swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by metaplex-foundation.
metaplex-foundation/solita-swift 1.0.4
Sol ana I DL t o A PI generator.
⭐️ 3
🕓 2 weeks ago
iOS macOS
.package(url: "https://github.com/metaplex-foundation/solita-swift.git", from: "1.0.4")

Solita Swift Swift

Sol ana I DL t o A PI generator.

How does it Work?

Solita generates a Swift SDK for your Solana Rust programs from the IDL extracted by anchor.

It supports Anchor/Shank IDls and will output a SPM package generated. It includes Accounts, Errors, Instructions and Types. It uses a a default borsch serializer called beet also included in the package.

Its a carbon copy from Solita with lots of language specific considerations. IDL processing and architecture has been maintained.

Usage

Run solita cli against the idl.json generated by shank or solita

solita render <idlPath> <outputDir>

For example

solita render Tests/SolitaTests/Resources/action_house.json .output

This will generate a swift package that contains a swift package of a library target. By default the target is called Generated. The package will contain the necessary dependencies to run the library that can be embedded into any project. Inside you will also get all the Sources of this generated code for this idl.

To change the package name please provide the package name option -p <packageName>

solita render Tests/SolitaTests/Resources/action_house.json .output -p ActionHouse

Inside the Sources you will also get a .swiftlint that have the following disabled_rules.

disabled_rules:
 - identifier_name
 - force_cast

Currently there is no way to change the name scheme for the identifiers. Casting is also necessary since the parsing requires it.

Please verify your Program.swift and check if is pointing to the default onchain program. If the publicKey is provided by the IDL it will be shown here. If is not, please provided it or it will throw an exception during runtime.

import Foundation
import Solana

/**
* Program address
*
* @category constants
* @category generated
*/

let PROGRAM_ADDRESS = "<publickey>"

/**
* Program public key
*
* @category constants
* @category generated
*/

public let PROGRAM_ID = PublicKey(string: PROGRAM_ADDRESS)

Options

Option Short Long Value
Project Name -p --projectName String
AccountsHaveImplicitDiscriminator -a --accountsHaveImplicitDiscriminator True or False
Program Id -i --programId String

Build from Source

Run the following command on shell to compile

swift build -c release

the output binary file will be here .build/release/SolitaCLI

Errors

If you receive the following error:

error: 'solita-swift': Invalid manifest
.../solita-swift/Package.swift:2:8: error: no such module 'PackageDescription'

Running the following command should resolve the issue:

sudo xcode-select --reset

LICENSE

Apache-2.0

GitHub

link
Stars: 3
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Solita 1.0.4
2 weeks ago

What's Changed

Full Changelog: https://github.com/metaplex-foundation/solita-swift/compare/1.0.3...1.0.4

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics