Skip to content
Protobuf definition for IoTeX transaction and gRPC API
Go Makefile
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
golang add election api (#43) Sep 30, 2019
proto
.gitignore Add go mod and dep ensure May 4, 2019
LICENSE Initial commit May 3, 2019
Makefile
README.md
go.mod
go.sum Remove grpc-gateway hook/stub (#15) May 28, 2019

README.md

iotex-proto

Protobuf and utility package for IoTeX blockchain transaction and gRPC API

  • \proto includes protobuf definition for all core data objects and gRPC API used by IoTeX blockchain

  • \golang includes the generated protobuf files for go language

Getting Started

Installing

Install the Google protocol buffers compiler protoc v3.0.0 or above from https://github.com/protocolbuffers/protobuf/releases

Enable go mod. Install grpc-gateway https://github.com/grpc-ecosystem/grpc-gateway. Basically this is what you need:

go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go get -u github.com/golang/protobuf/protoc-gen-go

Compiling

make gogen

This generates the protobuf files and put into \golang directory

Sign IoTeX blockchain transaction

secp256k1 ECDSA algorithm is used by IoTeX blockchain to sign and verify transaction. The signature of an IoTeX transaction is computed as the secp256k1 signature of hash of raw transaction

signature = secp256k1.Sign(hash of raw transaction)

The signature is in 65-byte [R, S, V] format where the last byte V is the recovery id for public key recovery

The following guide used sender address io1mwekae7qqwlr23220k5n9z3fmjxz72tuchra3m and recipient address io187wzp08vnhjjpkydnr97qlh8kh0dpkkytfam8j as example. Replace your actual address and recipient address when creating and signing the transaction

Create raw transaction

  1. construct a message Transfer as defined in \proto\type\action.proto, amount is in unit of 10^-18 IOTX token

For example, to transfer 1.2 IOTX token, set amount = “1200000000000000000”

Set recipient = "io187wzp08vnhjjpkydnr97qlh8kh0dpkkytfam8j"

payload = hex-bytes of message you want to attach to transaction, can be nil/NULL

  1. construct a message ActionCore as defined in \proto\type\action.proto, with action = transfer message in 1

Set version = 1, gasLimit = 10000, gasPrice = 1000000000000, that is 0.000001 IOTX

For nonce, issue a gRPC request GetAccount(GetAccountRequest) as defined in \proto\api\api.proto use the value of "pendingNonce" field in the reply

Sign raw transaction

  1. serialize the ActionCore message using protobuf
bytes = proto.Serialize(ActionCore message above)
  1. hash of raw transaction is computed as the 32-byte Keccak256 hash of the bytes
hash = Keccak256(bytes)
  1. sign the hash using sender's private key
sig = secp256k1.Sign(hash)

Send signed transaction to IoTeX blockchain

  1. construct a message Action as defined in \proto\type\action.proto

Set action = ActionCore above, senderPubKey = bytes representation of sender's public key, signature = sig above

  1. issue a gRPC request SendAction(SendActionRequest) to IoTeX blockchain endpoint

Go example

The examples folder contains a few examples demonstrating functionality.

To run an example, navigate to it's directory, then go run the file. For example:

$ cd golang/examples/transfer
$ go run main.go
You can’t perform that action at this time.