effectai / neo-clojure-clr

Clojure CLR functions for interactive development on the NEO blockchain

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Clojure CLR - NEO

Functions and tooling for NEO in Clojure, using the NEO core codebase.

Aims to add extra functionality to neo-cli and make interaction with the blockchain more easy and fun.

Status

The code is in active development, pre-alpha. It should not be used for anything critical. Please only use it in a private blockchain environment for now.

Features

The following functionality is included:

Getting Started

Installation

It’s hightly recommended to use the Docker image when running the project, as setting up Clojure CLR with NEO can be tricky. Make sure you have Docker 17.05 or above installed, then run the following commands:

$ git clone https://github.com/effectai/neo-clojure-clr
$ cd neo-clojure-clr
$ docker build . -t neo-clj-clr
$ docker run --rm -it neo-clj-clr
REPL 0.0.0.0:11217
user>

This leaves you with a Clojure REPL in user namespace.

Setup

The application assumes you have neo-privatenet-docker running with an RPC server enabled on http://localhost:10332.

To interact with the blockchain you’ll need to load some namespaces. The examples below will assume the following setup:

user> (require '[neo-clj.core :as neo-clj]) 
user> (require '[neo-clj.blockchain :as bc]) 
user> (require '[neo-clj.rpc :as rpc])
user> (require '[neo-clj.wallet :as wallet])

Examples

Load and sync blockchain

user> (def b (bc/create))
#'user/b
user> (bc/sync b)
load block 0 of 1534
...
...
load block 1534 of 1534
nil

Create a wallet

user> (def w (wallet/create "wallet.db3" "pass"))
#'user/w

Claim initial NEO

user> (def to (wallet/get-a-public-key w))
#'user/to
user> (def claim-tx (neo-clj/claim-initial-neo-tx to))
#'user/claim-tx
user> (bc/relay (:ctx claim-tx))
true
user> (bc/sync b)
... 
...
user> (wallet/neo-balance w)
100000000

Start an RPC server

user> (def server (rpc/create-server {:port 10336}))
#'user/server
user> (rpc/start-server server)
Starting extended RPC server on port 10336

RPC reference

The RPC server exposes the same methods as in the neo core server. In addition the following endpoints are available in neo-clj:

commandparametersdescription
getassetslist all registered assets
getkeysget all keys in rpc wallet
makekeys<num> (optional)add <num> new keys in rpc wallet
claimgas<address> (optional)claim gas for rpc wallet. if address is omitted, all addresses are used

About

Clojure CLR functions for interactive development on the NEO blockchain

License:MIT License


Languages

Language:Clojure 100.0%