Sol ana I DL t o A PI generator.
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.
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 .outputThis 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 ActionHouseInside the Sources you will also get a .swiftlint that have the following disabled_rules.
disabled_rules:
- identifier_name
- force_castCurrently 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)| Option | Short | Long | Value |
|---|---|---|---|
| Project Name | -p | --projectName | String |
| AccountsHaveImplicitDiscriminator | -a | --accountsHaveImplicitDiscriminator | True or False |
| Program Id | -i | --programId | String |
Run the following command on shell to compile
swift build -c releasethe output binary file will be here .build/release/SolitaCLI
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 --resetApache-2.0