From 8f3b488023355358fccb636869c0eb1697853832 Mon Sep 17 00:00:00 2001 From: Slavomir Date: Sun, 10 Oct 2021 20:32:59 +0200 Subject: [PATCH] Improve README --- README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/README.md b/README.md index e2fd718..e34ca0d 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,51 @@ $ cd my-project $ go get github.com/gagliardetto/solana-go@v0.5.1 ``` +## Pretty-Print transactions/instructions + +![pretty-printed](https://user-images.githubusercontent.com/15271561/136708519-399c9498-3d20-48d6-89fa-bdf43aac6d83.png) + +Instructions can be pretty-printed with the `EncodeTree` method on a `Transaction`: + +```go +tx, err := solana.NewTransaction( + []solana.Instruction{ + system.NewTransferInstruction( + amount, + accountFrom.PublicKey(), + accountTo, + ).Build(), + }, + recent.Value.Blockhash, + solana.TransactionPayer(accountFrom.PublicKey()), +) + +... + +// Pretty print the transaction: +tx.EncodeTree(text.NewTreeEncoder(os.Stdout, "Transfer SOL")) +``` + +## SendAndConfirmTransaction + +You can wait for a transaction confirmation using the `sne` package tools (for a complete example: [see here](#transfer-sol-from-one-wallet-to-another-wallet)) + +```go +// Send transaction, and wait for confirmation: +sig, err := confirm.SendAndConfirmTransaction( + context.TODO(), + rpcClient, + wsClient, + tx, +) +if err != nil { + panic(err) +} +spew.Dump(sig) +``` + +The above command will send the transaction, and wait for its conformation. + ## Examples ### Create account (wallet)