Skip to content

An IPFS client/api Swift Package. Originally bundled with GraniteUI, pulled out for independant use by any party.

License

Notifications You must be signed in to change notification settings

nonfungibletunji/IPFSKit

 
 

Repository files navigation

IPFSKit

Travis CI Build Swift 5.3 xcode-version

Based on: https://github.com/ipfs-shipyard/swift-ipfs-http-client Converted into a standalone Swift Package.

Installation

Add this repo link as a swift package to your XCode project.

Requirements

- iOS 12 or later
- macOS BigSur or later

Usage

import IPFSKit

let client: IPFSClient?
    
public init() {
    client = try? IPFSClient.init(host: "ipfs.infura.io", port: 5001, ssl: true)
}

Adding data to IPFS

if let data = result.data.pngData() {
    do {
        try state.service.client?.add(data) { nodes in // Adding data to IPFS
            // use 'nodes' to pin content
        }
    } catch let error {
        GraniteLogger.info("error adding new image:\n\(error)", .expedition, focus: true)
    }
}

Convert any type of object into a Data type to prepare for adding.

Pinning data to IPFS

do {
    if let addHash = nodes.first?.hash { // the `nodes` from the closure of the previous code example
        try client?.pin.add(addHash) { pinHash in
            let gatewayHash = b58String(pinHash) // IPFS public hash gateway for the pinned content
        }
    }
} catch let error {
    GraniteLogger.info("error pinning:\n\(error)", .expedition, focus: true)
}

About

An IPFS client/api Swift Package. Originally bundled with GraniteUI, pulled out for independant use by any party.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 100.0%