irys

package module
v1.5.10 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2023 License: MIT Imports: 25 Imported by: 0

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).

Currency arweave ethereum matic bnb avalanche solana arbitrum fantom near algorand aptos
Price API x x x x x - x x - - -
Balance API x x x x x - x x - - -
Upload File API - x x x x - x x - - -
Chunk File API - x x x x - x x - - -
Upload Folder API - - - - - - - - - - -
Widthdraw API - - - - - - - - - - -
Get Receipt API - x x x x - x x - - -
Verify Receipt API - - - - - - - - - - -
Found API - x x x x - x x - - -

Install

go get -u  github.com/Ja7ad/irys

Examples

example of irys sdk in golang

Upload
package main

import (
	"bufio"
	"context"
	"fmt"
	"io"
	"log"
	"os"
	"time"

	"github.com/Ja7ad/irys"
	"github.com/Ja7ad/irys/configs"
	"github.com/Ja7ad/irys/currency"
)

func main() {
	matic, err := currency.NewMatic("ExamplePrivateKey", "ExampleRpc")
	if err != nil {
		log.Fatal(err)
	}

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

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

	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
	defer cancel()

	stat, err := file.Stat()
	if err != nil {
		log.Fatal(err)
	}

	bs := make([]byte, stat.Size())
	_, err = bufio.NewReader(file).Read(bs)
	if err != nil && err != io.EOF {
		log.Fatal(err)
	}

	tx, err := c.BasicUpload(ctx, bs)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(tx)
}

Download
package main

import (
	"context"
	"fmt"
	"io"
	"log"

	"github.com/Ja7ad/irys"
	"github.com/Ja7ad/irys/configs"
	"github.com/Ja7ad/irys/currency"
)

func main() {
	matic, err := currency.NewMatic("ExamplePrivateKey", "ExampleRpc")
	if err != nil {
		log.Fatal(err)
	}

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

	file, err := c.Download(context.Background(), "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(len(b), file.Header, file.ContentLength, file.ContentType)
}
Calculate Price
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/Ja7ad/irys"
	"github.com/Ja7ad/irys/configs"
	"github.com/Ja7ad/irys/currency"
)

func main() {
	matic, err := currency.NewMatic("ExamplePrivateKey", "ExampleRpc")
	if err != nil {
		log.Fatal(err)
	}
	c, err := irys.New(irys.DefaultNode1, matic, false)
	if err != nil {
		log.Fatal(err)
	}

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

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

import (
	"context"
	"fmt"
	"log"

	"github.com/Ja7ad/irys"
	"github.com/Ja7ad/irys/configs"
	"github.com/Ja7ad/irys/currency"
)

func main() {
	matic, err := currency.NewMatic("ExamplePrivateKey", "ExampleRpc")
	if err != nil {
		log.Fatal(err)
	}

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

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

	fmt.Println(tx)
}
Perform TopUp
package main

import (
	"context"
	"fmt"
	"log"
	"math/big"

	"github.com/Ja7ad/irys"
	"github.com/Ja7ad/irys/currency"
)

func main() {
	matic, err := currency.NewMatic("ExamplePrivateKey", "ExampleRpc")
	if err != nil {
		log.Fatal(err)
	}

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

	ctx := context.Background()

	err = c.TopUpBalance(ctx, big.NewInt(321000000000023))
	if err != nil {
		log.Fatal(err)
	}

	balance, err := c.GetBalance(ctx)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(balance)
}

Todo

  • arweave network
  • ethereum network
  • polygon matic network
  • concurrent and chunk upload
  • get chunk upload transaction response
  • fix bug finish chunk upload for finalizing
  • 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 Client added in v0.5.1

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

func (*Client) BasicUpload added in v0.5.1

func (c *Client) BasicUpload(ctx context.Context, file []byte, tags ...types.Tag) (types.Transaction, error)

func (*Client) ChunkUpload added in v0.5.1

func (c *Client) ChunkUpload(ctx context.Context, file io.Reader, chunkId string, tags ...types.Tag) (types.Transaction, error)

func (*Client) Close added in v0.5.2

func (c *Client) Close()

func (*Client) Download added in v0.5.1

func (c *Client) Download(ctx context.Context, txId string) (*types.File, error)

func (*Client) GetBalance added in v0.5.1

func (c *Client) GetBalance(ctx context.Context) (*big.Int, error)

func (*Client) GetMetaData added in v0.5.1

func (c *Client) GetMetaData(ctx context.Context, txId string) (types.Transaction, error)

func (*Client) GetPrice added in v0.5.1

func (c *Client) GetPrice(ctx context.Context, fileSize int) (*big.Int, error)

func (*Client) GetReceipt added in v0.5.6

func (c *Client) GetReceipt(ctx context.Context, txId string) (types.Receipt, error)

func (*Client) TopUpBalance added in v0.5.1

func (c *Client) TopUpBalance(ctx context.Context, amount *big.Int) error

func (*Client) Upload added in v0.5.1

func (c *Client) Upload(ctx context.Context, file []byte, tags ...types.Tag) (types.Transaction, error)

type Irys

type Irys interface {
	// GetPrice return fee base on fileSize in byte for selected currency
	GetPrice(ctx context.Context, 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 []byte, tags ...types.Tag) (types.Transaction, error)
	// Upload file with check balance
	Upload(ctx context.Context, file []byte, tags ...types.Tag) (types.Transaction, error)
	// ChunkUpload upload file chunk concurrent for big files (min size: 500 KB, max size: 95 MB)
	//
	// chunkId used for resume upload, chunkId expired after 30 min.
	//
	// Note: this feature is experimental, maybe not work.
	ChunkUpload(ctx context.Context, file io.Reader, chunkId string, tags ...types.Tag) (types.Transaction, error)

	// Download get file with header details
	Download(ctx context.Context, txId string) (*types.File, error)
	// GetMetaData get transaction details
	GetMetaData(ctx context.Context, txId string) (types.Transaction, error)

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

	// GetReceipt get receipt information from node
	GetReceipt(ctx context.Context, txId string) (types.Receipt, error)

	// Close stop irys client request
	Close()
}

func New

func New(node Node, currency currency.Currency, debug bool, options ...Option) (Irys, error)

New create IrysClient object

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

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

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

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 *Client)

func WithCustomClient

func WithCustomClient(c *http.Client) Option

WithCustomClient set custom http client for irys

func WithCustomLogging added in v0.5.1

func WithCustomLogging(logging logger.Logger) Option

WithCustomLogging create custom logging

func WithCustomRetryMax added in v0.4.0

func WithCustomRetryMax(retry int) Option

WithCustomRetryMax maximum number of retries

func WithCustomRetryWaitMax added in v0.4.0

func WithCustomRetryWaitMax(waitMax time.Duration) Option

WithCustomRetryWaitMax maximum time to wait

func WithCustomRetryWaitMin added in v0.4.0

func WithCustomRetryWaitMin(waitMin time.Duration) Option

WithCustomRetryWaitMin minimum time to wait

Directories

Path Synopsis
_example
utils

Jump to

Keyboard shortcuts

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