Skip to content

Commit

Permalink
docs: show how to use the SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
randomshinichi committed Apr 9, 2019
1 parent 45ff92d commit 7895e74
Showing 1 changed file with 41 additions and 12 deletions.
53 changes: 41 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,56 @@ golang sdk for aeternity blockchain
[![Go Report Card](https://goreportcard.com/badge/github.com/aeternity/aepp-sdk-go)](https://goreportcard.com/report/github.com/aeternity/aepp-sdk-go) [![GoDoc](https://godoc.org/github.com/aeternity/aepp-sdk-go?status.svg)](https://godoc.org/github.com/aeternity/aepp-sdk-go)


## Usage
No matter what kind of transaction you're making, it always follows the same rules:
1. Find the account nonce, get the transaction TTL (in blocks)
2. Make the transaction
3. Sign the transaction with a given network ID
4. Broadcast it to a node of your choosing

```
acc, err := aeternity.AccountFromHexString(senderPrivateKey)
if err != nil {
fmt.Println(err)
return
}
aeClient := aeternity.NewCli("http://localhost:3013", false).WithAccount(acc)
```

Most parameters are set by modifying the variables in `config.go` in this manner:
`aeternity.Config.Client.Fee = *utils.RequireBigIntFromString("100000000000000")`

When using the `Ae/Aens/Contract/Oracle` struct helper functions in `helpers.go`, chores like getting the TTL, Account Nonce, encoding of the AENS claim etc are done automatically.
```
preclaimTx, salt, err := aeClient.Aens.NamePreclaimTx("fdsa.test", aeternity.Config.Client.Fee)
if err != nil {
fmt.Println(err)
return
}
preclaimTxStr, err := aeternity.BaseEncodeTx(&preclaimTx)
signedTxStr, hash, signature, err := aeternity.SignEncodeTxStr(acc, preclaimTxStr, "ae_docker")
if err != nil {
fmt.Println(err)
return
}
err = aeClient.BroadcastTransaction(signedTxStr)
if err != nil {
panic(err)
}
```

## Development

download the latest openapi spcecifications
download the latest openapi specifications

```
curl https://sdk-edgenet.aepps.com/api -o api/swagger.json
```

replace every integer (int64) with a uint64 in the swagger.json (except for time)
generate the client (using [go-swagger](https://github.com/go-swagger/go-swagger))

```
rm -rf generated/* && swagger generate client -f api/swagger.json -A node --with-flatten=minimal --target generated --tags=external --api-package=operations --client-package=client
```

## Structure
No matter what kind of transaction you're making, it always follows the same rules:
1. Find the account nonce, get the transaction TTL (in blocks)
2. Make the transaction
3. Sign the transaction with a given network ID
4. Broadcast it to a node of your choosing

The functions in `aeternity/helpers.go` will help you with these 4 steps, wrapping away the raw implementation details. They use the more barebones functions in `aeternity/transactions.go`.

0 comments on commit 7895e74

Please sign in to comment.