All Projects → go-steem → Rpc

go-steem / Rpc

Licence: mit
Golang RPC client library for Steem - https://steem.io

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Labels

Projects that are alternatives of or similar to Rpc

finallycomments
Add Steem Comments To Any Website/Blog
Stars: ✭ 15 (-69.39%)
Mutual labels:  steem
Ditch
Create and broadcast transactions to Graphene-based blockchains
Stars: ✭ 32 (-34.69%)
Mutual labels:  steem
Dtube
📺 d.tube app. A full-featured video sharing website, decentralized.
Stars: ✭ 569 (+1061.22%)
Mutual labels:  steem
alpha-web
1Ramp Alpha Web App
Stars: ✭ 19 (-61.22%)
Mutual labels:  steem
steem-wise-core
Vote delegation system for STEEM blockchain: core library for nodejs & browser use
Stars: ✭ 17 (-65.31%)
Mutual labels:  steem
Busy
Blockchain-based social network where anyone can earn rewards 🚀
Stars: ✭ 343 (+600%)
Mutual labels:  steem
steem-python
A Python library/toolkit for the Steem blockchain
Stars: ✭ 18 (-63.27%)
Mutual labels:  steem
Dtube Mobile Unofficial
D.tube client app for Android
Stars: ✭ 35 (-28.57%)
Mutual labels:  steem
esteem
eSteem Mobile - Application for Android and iOS users, start earning cryptocurrency!
Stars: ✭ 88 (+79.59%)
Mutual labels:  steem
Condenser
The greatest application front-end to the Steem Blockchain.
Stars: ✭ 516 (+953.06%)
Mutual labels:  steem
steemprojects.com
Steem Projects is a directory of apps, sites and tools build by Steem community
Stars: ✭ 27 (-44.9%)
Mutual labels:  steem
steemsnippets
A collection of snippets for steem programming
Stars: ✭ 44 (-10.2%)
Mutual labels:  steem
Production
Production app for D.Tube
Stars: ✭ 354 (+622.45%)
Mutual labels:  steem
steem-bot
Easy automation on top of Steem blockchain
Stars: ✭ 55 (+12.24%)
Mutual labels:  steem
Sscjs
a light javascript library to interact with the Steem Smart Contracts Sidechain
Stars: ✭ 19 (-61.22%)
Mutual labels:  steem
exxp
A plugin to bring wordpress and hive together.
Stars: ✭ 30 (-38.78%)
Mutual labels:  steem
steem-php
PHP Library for the Steem blockchain RPC
Stars: ✭ 13 (-73.47%)
Mutual labels:  steem
Mydicebot.github.io
★MyDiceBot★ - Ultimate Bitcoin Dice Bot. Bet More, Earn More!
Stars: ✭ 48 (-2.04%)
Mutual labels:  steem
Api.steemjs.com
REST API for Steem blockchain
Stars: ✭ 28 (-42.86%)
Mutual labels:  steem
Steem Js
Steem.js the official JavaScript library for Steem blockchain
Stars: ✭ 481 (+881.63%)
Mutual labels:  steem

go-steem/rpc

GoDoc

Golang RPC client library for Steem.

Compatibility

steemd 0.13.0

Usage

import "github.com/go-steem/rpc"

This package is still very much in development, so gopkg.in is not yet available.

Installation

This package calls bitcoin-core/secp256k1 using CGO to implement signed transactions, so you need to install secp256k1 first. Then it will be possible to build go-steem/rpc.

In case you don't need signed transactions, i.e. you don't need to use network_broadcast_api, it is possible to build the package with nosigning tag to exclude the functionality:

$ go build -tags nosigning

Example

This is just a code snippet. Please check the examples directory for more complete and ready to use examples.

// Instantiate the WebSocket transport.
t, _ := websocket.NewTransport("ws://localhost:8090")

// Use the transport to create an RPC client.
client, _ := rpc.NewClient(t)
defer client.Close()

// Call "get_config".
config, _ := client.Database.GetConfig()

// Start processing blocks.
lastBlock := 1800000
for {
	// Call "get_dynamic_global_properties".
	props, _ := client.Database.GetDynamicGlobalProperties()

	for props.LastIrreversibleBlockNum-lastBlock > 0 {
		// Call "get_block".
		block, _ := client.Database.GetBlock(lastBlock)

		// Process the transactions.
		for _, tx := range block.Transactions {
			for _, op := range tx.Operations {
				switch body := op.Data().(type) {
					// Comment operation.
					case *types.CommentOperation:
						content, _ := client.Database.GetContent(body.Author, body.Permlink)
						fmt.Printf("COMMENT @%v %v\n", content.Author, content.URL)

					// Vote operation.
					case *types.VoteOperation:
						fmt.Printf("VOTE @%v @%v/%v\n", body.Voter, body.Author, body.Permlink)

					// You can add more cases, it depends on what
					// operations you actually need to process.
				}
			}
		}

		lastBlock++
	}

	time.Sleep(time.Duration(config.SteemitBlockInterval) * time.Second)
}

Package Organisation

You need to create a Client object to be able to do anything. To be able to instantiate a Client, you first need to create a transport to be used to execute RPC calls. The WebSocket transport is available in transports/websocket. Then you just need to call NewClient(transport).

Once you create a Client object, you can start calling the methods exported via steemd's RPC endpoint by invoking associated methods on the client object. There are multiple APIs that can be exported, e.g. database_api and login_api, so the methods on the Client object are also namespaced accoding to these APIs. For example, to call get_block from database_api, you need to use Client.Database.GetBlock method.

When looking for a method to call, all you need is to turn the method name into CamelCase, e.g. get_config becomes Client.Database.GetConfig.

Raw and Full Methods

There are two methods implemented for every method exported via the RPC endpoint. The regular version and the raw version. Let's see an example for get_config:

func (client *Client) GetConfig() (*Config, error) {
	...
}

func (client *Client) GetConfigRaw() (*json.RawMessage, error) {
	...
}

As we can see, the difference is that the raw version returns *json.RawMessage, so it is not trying to unmarshall the response into a properly typed response.

There are two reasons for this:

  1. To be able to see raw data.
  2. To be able to call most of the remote methods even though the response object is not yet known or specified.

It is already benefitial to just have the raw version because at least the method parameters are statically typed.

Status

This package is still under rapid development and it is by no means complete. For now there is no promise considering API stability. Some response objects maybe be typed incorrectly. The package is already usable, though. See the examples directory.

To check the API coverate, please check the README files in the relevat API package in the apis subdirectory.

License

MIT, see the LICENSE file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].