Giter Club home page Giter Club logo

iotex-antenna-go's Introduction

iotex-antenna-go

CircleCI Go version LICENSE

This is the the official Go implementation of IoTeX SDK! Please refer to IoTeX whitepaper and the protocol for details.

Get Started

Minimum Requirements

Components Version Description
Golang โ‰ฅ 1.11.5 Go programming language

Add Dependency

// go mod
go get github.com/iotexproject/iotex-antenna-go/v2

Code It Up

The below example code shows the 4 easy steps to send a transaction to IoTeX blockchain

  1. connect to the chain's RPC endpoint
  2. create an account by importing a private key
  3. create a client and generate an action sender
  4. send the transaction to the chain
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/iotexproject/iotex-address/address"
	"github.com/iotexproject/iotex-antenna-go/v2/account"
	"github.com/iotexproject/iotex-antenna-go/v2/iotex"
	"github.com/iotexproject/iotex-proto/golang/iotexapi"
)

const (
	mainnetRPC     = "api.iotex.one:443"
	testnetRPC     = "api.testnet.iotex.one:443"
	mainnetChainID = 1
	testnetChainID = 2
)

func main() {
	// Create grpc connection
	conn, err := iotex.NewDefaultGRPCConn(testnetRPC)
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close()

	// Add account by private key
	acc, err := account.HexStringToAccount("...")
	if err != nil {
		log.Fatal(err)
	}

	// create client
	c := iotex.NewAuthedClient(iotexapi.NewAPIServiceClient(conn), testnetChainID, acc)
	
	// send the transfer to chain
	to, err := address.FromString("io1zq5g9c5c3hqw9559ks4anptkpumxgsjfn2e4ke")
	if err != nil {
		log.Fatal(err)
	}
	hash, err := c.Transfer(to, big.NewInt(10)).SetGasPrice(big.NewInt(100000000000)).SetGasLimit(20000).Call(context.Background())
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("transaction hash = %x\n", hash)
}

More Examples

There are three examples demostrating the use of this SDK on Testnet. You can make examples to build and try:

  • ./examples/chaininfo shows how to use the SDK to pull chain, block, action and delegates info
  • ./examples/openoracle shows how to deploy and invoke Open Oracle Contracts
  • ./examples/xrc20tokens shows how to deploy and invoke XRC20 tokens

iotex-antenna-go's People

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.