irys

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 16 Imported by: 1

README

irys-go Go Reference

Go Implementation SDK of Irys network, irys is the only provenance layer. It enables users to scale permanent data and precisely attribute its origin (arweave bundlr).

Install

go get -u  github.com/Ja7ad/irys

Examples

example of irys sdk in golang

Upload
package main

import (
	"context"
	"fmt"
	"github.com/Ja7ad/irys"
	"github.com/Ja7ad/irys/token"
	"log"
	"os"
)

func main() {
	matic, err := token.NewMatic(
		"foo",
		"bar")
	if err != nil {
		log.Fatal(err)
	}

	c, err := irys.New(irys.DefaultNode2, matic)
	if err != nil {
		log.Fatal(err)
	}

	file, err := os.Open("image.jpeg")
	if err != nil {
		log.Fatal(err)
	}

	tx, err := c.BasicUpload(context.Background(), file)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(tx)

}
Download
package main

import (
	"fmt"
	"github.com/Ja7ad/irys"
	"github.com/Ja7ad/irys/token"
	"io"
	"log"
)

func main() {
	matic, err := token.NewMatic("foo", "bar")
	if err != nil {
		log.Fatal(err)
	}
	c, err := irys.New(irys.DefaultNode2, matic)
	if err != nil {
		log.Fatal(err)
	}

	file, err := c.Download("XjzDyneweD_Dmhuaipbi7HyXXvsY6IkMcIsumlB0G2M")
	if err != nil {
		log.Fatal(err)
	}
	defer file.Data.Close()

	b, err := io.ReadAll(file.Data)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(string(b), file.Header, file.ContentLength, file.ContentType)
}
Calculate Price
package main

import (
	"fmt"
	"github.com/Ja7ad/irys"
	"github.com/Ja7ad/irys/token"
	"log"
)

func main() {
	matic, err := token.NewMatic("foo", "bar")
	if err != nil {
		log.Fatal(err)
	}
	c, err := irys.New(irys.DefaultNode1, matic)
	if err != nil {
		log.Fatal(err)
	}

	p, err := c.GetPrice(100000)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(p.Int64())
}
Get Metadata
package main

import (
	"fmt"
	"github.com/Ja7ad/irys"
	"github.com/Ja7ad/irys/token"
	"log"
)

func main() {
	matic, err := token.NewMatic("foo", "bar")
	if err != nil {
		log.Fatal(err)
	}
	c, err := irys.New(irys.DefaultNode2, matic)
	if err != nil {
		log.Fatal(err)
	}

	tx, err := c.GetMetaData("XjzDyneweD_Dmhuaipbi7HyXXvsY6IkMcIsumlB0G2M")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(tx)
}

Todo

  • arweave network
  • ethereum network
  • polygon matic network
  • concurrent and chunk upload
  • unit test
  • found API
  • upload folder
  • withdraw balance
  • get loaded balance

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gateway

type Gateway interface {
	// GetPrice return fee base on fileSize in byte for selected token
	GetPrice(fileSize int) (*big.Int, error)

	// BasicUpload file with calculate price and topUp balance base on price (this is slower for upload)
	BasicUpload(ctx context.Context, file io.Reader, tags ...types.Tag) (types.Transaction, error)
	// Upload file with check balance
	Upload(ctx context.Context, file io.Reader, price *big.Int, tags ...types.Tag) (types.Transaction, error)

	// Download get file with header details
	Download(hash string) (*types.File, error)
	// GetMetaData get transaction details
	GetMetaData(hash string) (types.Transaction, error)

	// GetBalance return current balance in irys node
	GetBalance() (*big.Int, error)
	// TopUpBalance top up your balance base on your amount in selected node
	TopUpBalance(ctx context.Context, amount *big.Int) (types.TopUpConfirmation, error)
}

func New

func New(node Node, token token.Token, options ...Option) (Gateway, error)

New create Irys object

Example
matic, err := token.NewMatic("foo", "bar")
if err != nil {
	log.Fatal(err)
}
c, err := New(DefaultNode1, matic)
if err != nil {
	log.Fatal(err)
}

p, err := c.GetPrice(100000)
if err != nil {
	log.Fatal(err)
}

fmt.Println(p.Int64())
Output:

type Irys

type Irys struct {
	// contains filtered or unexported fields
}

func (*Irys) BasicUpload added in v0.2.0

func (i *Irys) BasicUpload(ctx context.Context, file io.Reader, tags ...types.Tag) (types.Transaction, error)

func (*Irys) Download

func (i *Irys) Download(hash string) (*types.File, error)

func (*Irys) GetBalance added in v0.2.0

func (i *Irys) GetBalance() (*big.Int, error)

func (*Irys) GetMetaData

func (i *Irys) GetMetaData(hash string) (types.Transaction, error)

func (*Irys) GetPrice

func (i *Irys) GetPrice(fileSize int) (*big.Int, error)

func (*Irys) TopUpBalance added in v0.2.0

func (i *Irys) TopUpBalance(ctx context.Context, amount *big.Int) (types.TopUpConfirmation, error)

func (*Irys) Upload

func (i *Irys) Upload(ctx context.Context, file io.Reader, price *big.Int, tags ...types.Tag) (types.Transaction, error)

type Node added in v0.2.0

type Node string
const (
	DefaultNode1  Node = "https://node1.irys.xyz"  // DefaultNode1 is node 1 irys
	DefaultNode2  Node = "https://node2.irys.xyz"  // DefaultNode2 is node 2 irys
	DefaultDevNet Node = "https://devnet.irys.xyz" // DefaultDevNet is a testnet for test irys
)

type Option

type Option func(irys *Irys)

func WithCustomClient

func WithCustomClient(c *http.Client) Option

WithCustomClient set custom http client for irys

Directories

Path Synopsis
_example

Jump to

Keyboard shortcuts

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