Coder Social home page Coder Social logo

corerpc's Introduction

CoreRPC

Swift wrapper for the Bitcoin Core RPC.

Build:

swift build
swift test

# If you want an Xcode project
swift package generate-xcodeproj

Add to your own project with:

.package(url: "https://github.com/fanquake/CoreRPC", .branch("master"))
import CoreRPC
import PromiseKit

let node = URL(string: "http://localhost:18332") // testnet
let rpc = CoreRPC(url: node)

firstly {
    rpc.getVerboseBlock(hash: "0000000014e6ae5aef5b7b660b160b7572fe14b95609fefb6f87c2d2e33a5fdd")
}.done { block in
    print(block.confirmations, block.merkleroot)
    // 31165 "d20cdbe39d1528bacfab6f7a3c16d576aeae6e8fb993193692a918a7c5002450"

    let coinbase = block.tx.filter({ $0.isCoinbase() })
    print(coinbase.first!.txid)
    // "5b824f055bc4ea8763a817bd951c53f38f81d3c4f2066c6eee79acbad2819db7"
}.catch { err in
    print(err)
}

Configuration

The preferred configuration method is to set CORERPC_USER and CORERPC_PASS environment variables.

If found, they will be inserted into the given URL.

It is also possible to pass a fully formed URL, such as http://username:password@localhost:8332.

Swift Playground

An easy way to try this repo is with a Swift Playground.

git clone https://github.com/fanquake/CoreRPC.git

cd corerpc

swift package generate-xcodeproj
open CoreRPC.xcodeproj

Inside Xcode:

  • File -> New -> Playground
  • iOS (Blank) is fine.
  • Name the file Test.Playground and save it inside the corerpc directory.
    • Add to: CoreRPC
    • Group: CoreRPC
  • Create

Copy the following into the Playground:

import CoreRPC
import Foundation
import PlaygroundSupport
import PromiseKit

PlaygroundPage.current.needsIndefiniteExecution = true

Then you can use as normal. i.e:

let node = URL(string: "http://username:password@localhost:18332")!
let rpc = try CoreRPC.init(url: node)

firstly {
    rpc.getBlockHash(block: 554000)
}.then { hash in
    rpc.getVerboseBlock(hash: hash)
}.done { block in
    print("Tx count: \(block.tx.count)")
}.catch { error in
    print(error)
}

Playground

Testnet Block Explorer

An example block explorer application is available here.

corerpc's People

Contributors

fanquake avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.