-
Notifications
You must be signed in to change notification settings - Fork 6
/
example_test.go
38 lines (33 loc) · 1.01 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package zillean
import (
"fmt"
"math/big"
)
const endpoint = "https://api.zilliqa.com"
func Example() {
// generate a new account
toZil := NewZillean(endpoint)
toPrivKey := toZil.GeneratePrivateKey()
toPubKey, _ := toZil.GetPublicKeyFromPrivateKey(toPrivKey)
toAddress, _ := toZil.GetAddressFromPrivateKey(toPrivKey)
fmt.Printf("private key: %s\n", toPrivKey)
fmt.Printf("public key: %s\n", toPubKey)
fmt.Printf("address: %s\n", toAddress)
// use an existing account
fromZil := NewZillean(endpoint)
fromPrivKey := "AAFD338492962FAD674EE3BD6EBC57C8373B2C9BADBAC8806D890F1FE8C571DF"
fromPubKey, _ := fromZil.GetPublicKeyFromPrivateKey(fromPrivKey)
// create a transaction
rawTx := RawTransaction{
Version: 0,
Nonce: 1,
To: toAddress,
Amount: "1000000000000",
PubKey: fromPubKey,
GasPrice: big.NewInt(1000000000),
GasLimit: 1,
}
signature, _ := fromZil.SignTransaction(rawTx, fromPrivKey)
txID, _ := fromZil.RPC.CreateTransaction(rawTx, signature)
fmt.Printf("txID: %s\n", txID)
}