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

Contributors

chenyanchen avatar coderbradlee avatar coderzhi avatar dustinxie avatar koseoyoung avatar lizhefeng avatar neal-zhu avatar puncsky avatar ququzone avatar raullenchai avatar xuecanlong avatar yutongp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

iotex-antenna-go's Issues

[delegate] msg is not correct

when I update op address, it shows voting has been received. I didn't vote.
image

The message should be "your transaction has been received. Please wait for 5 mins. "

add three packages: antenna, iotx, utils

  1. add antenna package

antenna composites iotx like https://github.com/iotexproject/iotex-antenna/blob/master/src/antenna.ts

antenna is functioning like web3 package https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/web3/index.d.ts#L32

  1. add iotx package

iotx extends rpcmethod like https://github.com/iotexproject/iotex-antenna/blob/master/src/iotx.ts

  1. add utils package

add ToRau and FromRau in utils

implement unit conversion like /Users/tp/gocode/src/github.com/iotexproject/iotex-core/pkg/unit/unit.go and https://github.com/iotexproject/iotex-antenna/blob/master/src/account/utils.ts

undefined: secp256k1.RecoveryPubkey

Playing around with your sdk getting this err.
main.go

package main

import (
	"fmt"
	"log"

	"github.com/iotexproject/iotex-antenna-go/v2/account"
)

func main() {
	fmt.Println("hola")

	wal, err := account.NewAccount()
	if err != nil {
		log.Fatal(err.Error())
	}

	fmt.Printf("addr: %s", wal.Address())
}

go.mod:

module testing.iotex

go 1.17

require github.com/iotexproject/iotex-antenna-go/v2 v2.5.1

require (
	github.com/btcsuite/btcd v0.21.0-beta // indirect
	github.com/deckarep/golang-set v1.7.1 // indirect
	github.com/dustinxie/gmsm v1.4.0 // indirect
	github.com/ethereum/go-ethereum v1.10.4 // indirect
	github.com/go-stack/stack v1.8.0 // indirect
	github.com/google/uuid v1.1.5 // indirect
	github.com/iotexproject/go-pkgs v0.1.12 // indirect
	github.com/iotexproject/iotex-address v0.2.7 // indirect
	github.com/pkg/errors v0.9.1 // indirect
	github.com/rjeczalik/notify v0.9.2 // indirect
	golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
	golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 // indirect
)

go run main.go:

# github.com/iotexproject/go-pkgs/crypto
../../../go/pkg/mod/github.com/iotexproject/[email protected]/crypto/key.go:161:13: undefined: secp256k1.RecoverPubkey

Same with [email protected]

go version
go version go1.17 linux/amd64

Fix TestStake

=== RUN   TestStake
--- FAIL: TestStake (0.47s)
    require.go:248: 
        	Error Trace:	caller_staking_test.go:35
        	Error:      	An error is expected but got nil.
        	Test:       	TestStake

Improve client test coverage

Many tests in client_test.go are actually being skipped. Should remove the os.Getenv() in the test, and use actual mainnet data to verify correct gRPC API behavior and improve test coverage.

Please refer to TestServer_GetAccount() in commit eb84977 as an example.

To be more specific:

  1. TestServer_GetActions: use mainnet

  2. TestServer_GetAction: use mainnet hash 93de5923763c4ea79a01be023b49000838b1a4c22bdceed99dc23eeea8c9c757

  3. TestServer_GetActionsByAddress: use mainnet address io1066kus4vlyvk0ljql39fzwqw0k22h7j8wmef3n

  4. TestServer_GetUnconfirmedActionsByAddress: use mainnet address io1066kus4vlyvk0ljql39fzwqw0k22h7j8wmef3n

  5. TestServer_GetActionsByBlock: use mainnet block 89bbf8b1d3cbfb6020a1074a11c5430ef77eb220c00143dbd6f76d1cab94a1c2

  6. TestServer_GetBlockMetas: use mainnet

  7. TestServer_GetBlockMeta: use mainnet block 89bbf8b1d3cbfb6020a1074a11c5430ef77eb220c00143dbd6f76d1cab94a1c2

  8. TestServer_GetChainMeta: use mainnet

  9. TestServer_GetServerMeta: use mainnet

  10. TestServer_ReadState: use mainnet address io1066kus4vlyvk0ljql39fzwqw0k22h7j8wmef3n

  11. TestServer_GetReceiptByAction: use mainnet hash 246b9b47f390a6faee9d725d9637b00b7ec56fa7cdffe3d39aeaad277edbb8f4

  12. TestServer_ReadContract:
    skip this test for now b/c API has changed, re-enable after new gPRC API has been pushed to testnet/mainnet

  13. TestServer_SuggestGasPrice: use mainnet

  14. TestServer_EstimateGasForAction: use mainnet

  15. TestServer_GetEpochMeta: use mainnet

  16. TestServer_SendAction(): keep this on testnet

Remove iotex-core dependency

we recently moved some pkgs to iotexproject/go-pkgs and protobuf definition to iotexproject/iotex-proto
dependency to iotex-core can be removed as a result

Test response time

After an execution is sent to our chain, fetching action receipt by hash could take 5-10s. However, because of the async call for the db indexing and other delays (internet delay), it may take more than 10s for client. We would like to do a test on mainnet to tell the average response time, min response time, and max response time by calling multi-send contracts.

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.