Giter Site home page Giter Site logo

go-monero's Introduction

go-monero

GoDoc

A multi-platform Go library for interacting with Monero servers either on clearnet or not, supporting daemon and wallet RPC, p2p commands and ZeroMQ.

Quick start

Library

To consume go-monero as a library for your Go project:

go get -u -v github.com/duggavo/go-monero

go-monero exposes an high-level package: rpc.

The package rpc, is used to communicate with monerod and monero-wallet-rpc via its HTTP endpoints. Note that not all endpoints/fields are exposed on a given port - if it's being served in a restricted manner, you'll have access to less endpoints than you see in the documentation (daemon RPC, )

rpc itself is subdivided in two other packages: wallet and daemon, exposing monero-wallet-rpc and monerod RPCs accordingly.

For instance, to get the the height of the main chain:

package daemon_test

import (
	"context"
	"fmt"

	"github.com/duggavo/go-monero/rpc"
	"github.com/duggavo/go-monero/rpc/daemon"
)

func ExampleGetHeight() {
	ctx := context.Background()
	addr := "http://localhost:18081"

	// instantiate a generic RPC client
	client, err := rpc.NewClient(addr)
	if err != nil {
		panic(fmt.Errorf("new client for '%s': %w", addr, err))
	}

	// instantiate a daemon-specific client and call the `get_height`
	// remote procedure.
	height, err := daemon.NewClient(client).GetHeight(ctx)
	if err != nil {
		panic(fmt.Errorf("get height: %w", err))
	}

	fmt.Printf("height=%d hash=%s\n", height.Height, height.Hash)
}

And to get the height from monero-wallet-rpc:

package wallet_test

import (
	"context"
	"fmt"

	"github.com/duggavo/go-monero/rpc"
	"github.com/duggavo/go-monero/rpc/wallet"
)

func ExampleGetHeight() {
	ctx := context.Background()
	addr := "http://localhost:18086"

	// instantiate a generic RPC client
	client, err := rpc.NewClient(addr)
	if err != nil {
		panic(fmt.Errorf("new client for '%s': %w", addr, err))
	}

	// instantiate a wallet-specific client and call the `get_height`
	// remote procedure.
	height, err := wallet.NewClient(client).GetHeight(ctx)
	if err != nil {
		panic(fmt.Errorf("get height: %w", err))
	}

	fmt.Printf("height=%d\n", height.Height)
}

License

See LICENSE.

Thanks

Huge thanks to Ciro Costa for writing the original implementation!

go-monero's People

Contributors

duggavo avatar

Stargazers

 avatar  avatar  avatar SerHack avatar

Watchers

 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.