-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Julian Strobl <[email protected]>
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Library for RPC requests to Planetmint | ||
|
||
## How to use it | ||
|
||
In the example below we use the account `addr0` for which we have the private key in our keyring. | ||
The only keyring backend currently supported is the test backend under `keyring-test`. | ||
After that we construct three messages to send `10plmnt` each to three addresses `addr1`, `addr2` and `addr3`. | ||
We then change the default RPC endpoint to a remote one, build and sign the transaction and eventually send this transaction via RPC. | ||
For debugging purposes we print the transaction that we send as JSON and also the response from the RPC endpoint. | ||
|
||
``` | ||
package main | ||
import ( | ||
"fmt" | ||
"log" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
"github.com/planetmint/planetmint-go/lib" | ||
) | ||
func main() { | ||
addr0 := sdk.MustAccAddressFromBech32("plmnt168z8fyyzap0nw75d4atv9ucr2ye60d57dzlzaf") | ||
addr1 := sdk.MustAccAddressFromBech32("plmnt1vklujvmr9hsk9zwpquk4waecr2u5vcyjd8vgm8") | ||
addr2 := sdk.MustAccAddressFromBech32("plmnt1pwquxvqmmdry4gdel4g4rz0js7jy65453h92g7") | ||
addr3 := sdk.MustAccAddressFromBech32("plmnt1dyuhg8ldu3d6nvhrvzzemtc3893dys9v9lvdty") | ||
coin := sdk.NewCoins(sdk.NewInt64Coin("plmnt", 10)) | ||
msg1 := banktypes.NewMsgSend(addr0, addr1, coin) | ||
msg2 := banktypes.NewMsgSend(addr0, addr2, coin) | ||
msg3 := banktypes.NewMsgSend(addr0, addr3, coin) | ||
config := lib.GetConfig() | ||
config.SetRPCEndpoint("https://testnet-api.rddl.io") | ||
txBytes, txJSON, err := lib.BuildAndSignTx(addr0, msg1, msg2, msg3) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Println(txJSON) | ||
broadcastTxResponseJSON, err := lib.BroadcastTx(txBytes) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Println(broadcastTxResponseJSON) | ||
} | ||
``` |