Skip to content

Commit

Permalink
add transfer hbar example
Browse files Browse the repository at this point in the history
  • Loading branch information
QuestofIranon committed Feb 1, 2020
1 parent 0c666c3 commit 2282b1b
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions examples/transfer_hbar/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"fmt"
"github.com/hashgraph/hedera-sdk-go"
"os"
)

func main() {
operatorAccountID, err := hedera.AccountIDFromString(os.Getenv("OPERATOR_ID"))
if err != nil {
panic(err)
}

operatorPrivateKey, err := hedera.Ed25519PrivateKeyFromString(os.Getenv("OPERATOR_KEY"))
if err != nil {
panic(err)
}

fmt.Println("Crypto Transfer Example")

client := hedera.ClientForTestnet().
SetOperator(operatorAccountID, operatorPrivateKey)

fmt.Printf("Transferring 1 hbar from %v to 0.0.3\n", operatorAccountID)

transactionID, err := hedera.NewCryptoTransferTransaction().
AddSender(operatorAccountID, hedera.NewHbar(1)).
AddRecipient(hedera.AccountID{Account: 3}, hedera.NewHbar(1)).
SetTransactionMemo("go sdk example send_hbar/main.go").
Execute(client)

if err != nil {
panic(err)
}

receipt, err := transactionID.GetReceipt(client)

if err != nil {
panic(err)
}

fmt.Printf("crypto transfer status: %v\n", receipt.Status)
}

0 comments on commit 2282b1b

Please sign in to comment.