https://github.com/iotexproject/iotex-antenna-go
Golang SDK for IoTeX bloclchain
https://github.com/iotexproject/iotex-antenna-go
Last synced: about 1 year ago
JSON representation
Golang SDK for IoTeX bloclchain
- Host: GitHub
- URL: https://github.com/iotexproject/iotex-antenna-go
- Owner: iotexproject
- License: apache-2.0
- Created: 2019-03-01T23:19:26.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-09-07T15:49:04.000Z (almost 3 years ago)
- Last Synced: 2024-06-19T19:34:35.938Z (almost 2 years ago)
- Language: Go
- Size: 12.8 MB
- Stars: 12
- Watchers: 16
- Forks: 17
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# iotex-antenna-go
[](https://circleci.com/gh/iotexproject/iotex-antenna-go)
[](https://github.com/moovweb/gvm)
[](LICENSE)
This is the the official Go implementation of IoTeX SDK! Please refer to IoTeX [whitepaper](https://iotex.io/research) and the [protocol](https://github.com/iotexproject/iotex-core) for details.
## Get Started
### Minimum Requirements
| Components | Version | Description |
|----------|-------------|-------------|
| [Golang](https://golang.org) | ≥ 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](https://github.com/compound-finance/open-oracle)**
- `./examples/xrc20tokens` shows **how to deploy and invoke XRC20 tokens**