cardanogo

package module
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2022 License: GPL-3.0 Imports: 0 Imported by: 17

README

cardano-go

cardano-go is a library for creating go applicactions that interact with the Cardano Blockchain. [WIP]

Installation

$ go get github.com/echovl/cardano-node
$ go get github.com/echovl/cardano-node/node
$ go get github.com/echovl/cardano-node/tx

Quickstart

import (
	"fmt"

	"github.com/echovl/cardano-go/crypto"
	"github.com/echovl/cardano-go/node/blockfrost"
	"github.com/echovl/cardano-go/tx"
	"github.com/echovl/cardano-go/types"
)

func main() {
	// Node using blockfrost
	node := blockfrost.NewNode(types.Mainnet, "project-id")

	// New transaction builder
	builder := tx.NewTxBuilder(types.ProtocolParams{
		MinimumUtxoValue: 1000000,
		MinFeeA:          44,
		MinFeeB:          155381,
	})

	// Fetch node tip information
	tip, err := node.Tip()
	if err != nil {
		panic(err)
	}

	xprv, err := crypto.NewXPrvFromBech32("xpriv")
	if err != nil {
		panic(err)
	}
	txInputHash, err := types.NewHash32("tx-hash")
	if err != nil {
		panic(err)
	}
	sender, err := types.NewAddress("addr")
	if err != nil {
		panic(err)
	}
	receiver, err := types.NewAddress("addr")
	if err != nil {
		panic(err)
	}

	// Build inputs and ouputs
	txInput := tx.TransactionInput{TxHash: txInputHash, Index: 0, Amount: types.Coin(14838997)}
	txOutput := tx.TransactionOutput{Address: receiver, Amount: 1000000}

	// Add inputs and outputs
	builder.AddInputs(txInput)
	builder.AddOutputs(txOutput)

    // Add metadata
	builder.AddAuxiliaryData(&tx.AuxiliaryData{
		Metadata: tx.Metadata{
			0: map[string]interface{}{
				"number": 32,
				"string": "cardano-go",
			},
		},
	})

	// Set time to live
	builder.SetTTL(tip.Slot + uint64(100))

	// Sign transaction
	builder.Sign(xprv)

	// Add fee and change output if needed
	builder.AddFee(sender)

	// Build transaction
	tx, err := builder.Build()
	if err != nil {
		panic(err)
	}

	// Submit transaction to node
	txHash, err := node.SubmitTx(tx)
	if err != nil {
		panic(err)
	}

	fmt.Println(txHash)
}

cwallet

This package provides a cli cwallet for wallet management. It supports:

  • hierarchical deterministic wallets
  • fetching balances
  • transfering ADA
Configuration

cwallet uses blockfrost as a Node provider. It requires a config file in $XDG_CONFIG_HOME/cwallet.yml. Example:

blockfrost_project_id: "project-id"
Installation
$ git clone github.com/echovl/cardano-go
$ make && sudo make install
Usage

Wallet creation:

$ cwallet new-wallet jhon
mnemonic: various find knee churn bicycle current midnight visit artist help soon flower venture wasp problem

List wallet address:

$ cwallet list-address jhon
PATH                      ADDRESS
m/1852'/1815'/0'/0/0      addr1vxzfs9dj365gcdmv6dwj7auewf624ghwrtduecu37hrxsyst8gvu2

Send ADA:

$ cwallet transfer echo addr1vxzfs9dj365gcdmv6dwj7auewf624ghwrtduecu37hrxsyst8gvu2 2000000
fd3a7d6e9742fd9ddba2bd1740fa994f5c93a4f59bf88dc5f81d8d7413c5b3a9

Documentation

Overview

Package cardano-go is a library for the Cardano Blockchain.

Getting started

The best way to get started working with cardano-go is to use `go get` to add the library.

 go get github.com/echovl/cardano-go
	go get github.com/echovl/cardano-go/node
	go get github.com/echovl/cardano-go/tx

Hello cardano-go

This example shows how you can use cardano-go to query UTXOs.

package main

import (
    "fmt"

    "github.com/echovl/cardano-go/node/blockfrost"
    "github.com/echovl/cardano-go/types"
)

func main() {
    addr, err := types.NewAddress("addr1v9c7flddz5nqj448t78h5mdgau8p9ee24m7n62g2s48akkcjzfhw3")
    if err != nil {
        panic(err)
    }

    node := blockfrost.NewNode(types.Mainnet, "project-id")

    utxos, err := node.UTXOs(addr)
    if err != nil {
        panic(err)
    }

    fmt.Println(utxos)
}

Directories

Path Synopsis
cli
cmd
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL