Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
61dd7a8
feat(_code-samples): WiP add tx examples skeleton
banasa44 Jul 17, 2025
ff5b5ab
feat(_code-samples): WiP add go tx examples implementation
banasa44 Jul 17, 2025
877ed4e
feat(_code-samples): WiP add go tx examples implementation and get-st…
banasa44 Jul 21, 2025
d970039
refactor(_code-samples): remove Go WebSocket use-ticket example
banasa44 Jul 21, 2025
7e700c0
feat(docs): add GoLang tutorial link and logo to the documentation index
banasa44 Jul 22, 2025
82b9769
feat(docs): add xrpl-go GoLang package to XRPLF documentation site
banasa44 Jul 22, 2025
7baaa03
refactor(_code-samples): remove README.md file from code samples
banasa44 Jul 22, 2025
2e45eb7
refactor(_code-samples): move use-tickets example
banasa44 Jul 22, 2025
2aa7d5f
chore(docs): small fixes/changes in go tutorials docs
banasa44 Jul 22, 2025
79ed25b
chore(docs): small style and comments changes and fixes
banasa44 Jul 22, 2025
0ab8593
chore(docs): small fixes
banasa44 Jul 22, 2025
1009242
chore(docs): small fixes
banasa44 Jul 22, 2025
6de921c
feat(samples): add go examples, secure signing and send a memo
banasa44 Jul 22, 2025
e1153eb
chore(samples): replace tab for 4 spaces
banasa44 Jul 23, 2025
22d67e6
Apply suggestions from code review
banasa44 Aug 25, 2025
162a978
chore(code-samples): remove all emojis
banasa44 Aug 25, 2025
31be92a
chore(sample-docs): unify error handling with panic(err).
banasa44 Aug 25, 2025
0228e2e
fix(docs): correct terminology from "GoLang" to "Go" in tutorial file…
banasa44 Aug 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions _code-samples/batch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Batch

Code samples showing how to create and submit a [Batch transaction](../../docs/concepts/transactions/batch-transactions.md).
Both for simple and multi account batch transactions.
24 changes: 24 additions & 0 deletions _code-samples/batch/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module github.com/XRPLF

go 1.23.0

toolchain go1.23.10

require github.com/Peersyst/xrpl-go v0.1.11

require (
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e // indirect
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/tyler-smith/go-bip32 v1.0.0 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
golang.org/x/crypto v0.23.0 // indirect
)
58 changes: 58 additions & 0 deletions _code-samples/batch/go/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e h1:ahyvB3q25YnZWly5Gq1ekg6jcmWaGj/vG/MhF4aisoc=
github.com/FactomProject/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:kGUqhHd//musdITWjFvNTHn90WG9bMLBEPQZ17Cmlpw=
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec h1:1Qb69mGp/UtRPn422BH4/Y4Q3SLUrD9KHuDkm8iodFc=
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec/go.mod h1:CD8UlnlLDiqb36L110uqiP2iSflVjx9g/3U9hCI4q2U=
github.com/Peersyst/xrpl-go v0.1.11 h1:P6r/gHxRnbAtAdPmzNHz/7zpsdfvwh0SS+QI2JNT44w=
github.com/Peersyst/xrpl-go v0.1.11/go.mod h1:CBRM3/soqNeeL2Jx6USVUtECqulZVUoq3UxZKMz9hdw=
github.com/btcsuite/btcd/btcec/v2 v2.3.4 h1:3EJjcN70HCu/mwqlUsGK8GcNVyLVxFDlWurTXGPFfiQ=
github.com/btcsuite/btcd/btcec/v2 v2.3.4/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
github.com/decred/dcrd/crypto/ripemd160 v1.0.2 h1:TvGTmUBHDU75OHro9ojPLK+Yv7gDl2hnUvRocRCjsys=
github.com/decred/dcrd/crypto/ripemd160 v1.0.2/go.mod h1:uGfjDyePSpa75cSQLzNdVmWlbQMBuiJkvXw/MNKRY4M=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tyler-smith/go-bip32 v1.0.0 h1:sDR9juArbUgX+bO/iblgZnMPeWY1KZMUC2AFUJdv5KE=
github.com/tyler-smith/go-bip32 v1.0.0/go.mod h1:onot+eHknzV4BVPwrzqY5OoVpyCvnwD7lMawL5aQupE=
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
198 changes: 198 additions & 0 deletions _code-samples/batch/go/rpc/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
package main

import (
"fmt"

"github.com/Peersyst/xrpl-go/pkg/crypto"
"github.com/Peersyst/xrpl-go/xrpl/faucet"
"github.com/Peersyst/xrpl-go/xrpl/rpc"
"github.com/Peersyst/xrpl-go/xrpl/rpc/types"
"github.com/Peersyst/xrpl-go/xrpl/transaction"
txnTypes "github.com/Peersyst/xrpl-go/xrpl/transaction/types"
"github.com/Peersyst/xrpl-go/xrpl/wallet"
)

var (
CreatePaymentTx = func(sender, receiver *wallet.Wallet, amount txnTypes.CurrencyAmount) *transaction.Payment {
return &transaction.Payment{
BaseTx: transaction.BaseTx{
Account: sender.GetAddress(),
TransactionType: transaction.PaymentTx,
Flags: txnTypes.TfInnerBatchTxn,
},
Amount: amount,
Destination: receiver.GetAddress(),
}
}
)

func main() {
// Configure the client
cfg, err := rpc.NewClientConfig(
"https://s.devnet.rippletest.net:51234/",
rpc.WithFaucetProvider(faucet.NewDevnetFaucetProvider()),
)
if err != nil {
panic(err)
}
client := rpc.NewClient(cfg)

// Create and fund wallets
userWallet, err := wallet.New(crypto.ED25519())
if err != nil {
panic(err)
}

user2Wallet, err := wallet.New(crypto.ED25519())
if err != nil {
panic(err)
}

receiverWallet, err := wallet.New(crypto.ED25519())
if err != nil {
panic(err)
}

fmt.Println("Funding wallets...")
if err := client.FundWallet(&userWallet); err != nil {
panic(err)
}
if err := client.FundWallet(&user2Wallet); err != nil {
panic(err)
}
fmt.Println("Wallets funded")

// Check initial balances
userBalance, err := client.GetXrpBalance(userWallet.ClassicAddress)
if err != nil {
userBalance = "0"
}
user2Balance, err := client.GetXrpBalance(user2Wallet.ClassicAddress)
if err != nil {
user2Balance = "0"
}

receiverBalance, err := client.GetXrpBalance(receiverWallet.ClassicAddress)
if err != nil {
receiverBalance = "0"
}

fmt.Printf("User initial balance: %s XRP\n", userBalance)
fmt.Printf("User2 initial balance: %s XRP\n", user2Balance)
fmt.Printf("Receiver initial balance: %s XRP\n", receiverBalance)
fmt.Println()

fmt.Printf("Batch transaction test\n")

// Create test batch transaction
batchTx := &transaction.Batch{
BaseTx: transaction.BaseTx{
Account: txnTypes.Address(userWallet.ClassicAddress),
TransactionType: transaction.BatchTx,
},
RawTransactions: []txnTypes.RawTransaction{
{RawTransaction: CreatePaymentTx(&userWallet, &receiverWallet, txnTypes.XRPCurrencyAmount(5000000)).Flatten()},
{RawTransaction: CreatePaymentTx(&userWallet, &receiverWallet, txnTypes.XRPCurrencyAmount(5000000)).Flatten()},
},
}
batchTx.SetAllOrNothingFlag()

flattenedBatchTx := batchTx.Flatten()
fmt.Println("Autofilling flattened batch transaction...")
if err := client.Autofill(&flattenedBatchTx); err != nil {
panic(err)
}

fmt.Println("Signing batch transaction...")
response, err := client.SubmitTxAndWait(flattenedBatchTx, &types.SubmitOptions{
Autofill: false,
Wallet: &userWallet,
})
if err != nil {
panic(err)
}

fmt.Println("Batch transaction submitted")
fmt.Printf("Hash: %s\n", response.Hash.String())
fmt.Printf("Validated: %t\n", response.Validated)
fmt.Println()

// Check final balances
finalUserBalance, err := client.GetXrpBalance(userWallet.ClassicAddress)
if err != nil {
finalUserBalance = "0"
}
finalReceiverBalance, err := client.GetXrpBalance(receiverWallet.ClassicAddress)
if err != nil {
finalReceiverBalance = "0"
}

fmt.Printf("User final balance: %s XRP\n", finalUserBalance)

fmt.Printf("Receiver final balance: %s XRP\n", finalReceiverBalance)

fmt.Println()
fmt.Printf("Multisig Batch transaction test\n")

// Create test batch transaction
multiBatchTx := &transaction.Batch{
BaseTx: transaction.BaseTx{
Account: txnTypes.Address(userWallet.ClassicAddress),
TransactionType: transaction.BatchTx,
},
RawTransactions: []txnTypes.RawTransaction{
{RawTransaction: CreatePaymentTx(&userWallet, &receiverWallet, txnTypes.XRPCurrencyAmount(5000000)).Flatten()},
{RawTransaction: CreatePaymentTx(&user2Wallet, &receiverWallet, txnTypes.XRPCurrencyAmount(5000000)).Flatten()},
},
BatchSigners: []txnTypes.BatchSigner{
{
BatchSigner: txnTypes.BatchSignerData{
Account: txnTypes.Address(user2Wallet.ClassicAddress),
SigningPubKey: user2Wallet.PublicKey,
},
},
},
}
multiBatchTx.SetAllOrNothingFlag()

flattenedMultiBatchTx := multiBatchTx.Flatten()
fmt.Println("Autofilling flattened multi batch transaction...")
if err := client.AutofillMultisigned(&flattenedMultiBatchTx, 1); err != nil {
panic(err)
}

fmt.Println("Signing multi batch transaction...")
if err := wallet.SignMultiBatch(user2Wallet, &flattenedMultiBatchTx, nil); err != nil {
panic(err)
}

response, err = client.SubmitTxAndWait(flattenedMultiBatchTx, &types.SubmitOptions{
Autofill: false,
Wallet: &userWallet,
})
if err != nil {
panic(err)
}

fmt.Println("Multisig Batch transaction submitted")
fmt.Printf("Hash: %s\n", response.Hash.String())
fmt.Printf("Validated: %t\n", response.Validated)
fmt.Println()

// Check final balances
finalUser2Balance, err := client.GetXrpBalance(user2Wallet.ClassicAddress)
if err != nil {
finalUser2Balance = "0"
}
finalUserBalance, err = client.GetXrpBalance(userWallet.ClassicAddress)
if err != nil {
finalUserBalance = "0"
}
finalReceiverBalance, err = client.GetXrpBalance(receiverWallet.ClassicAddress)
if err != nil {
finalReceiverBalance = "0"
}
fmt.Printf("User final balance: %s XRP\n", finalUserBalance)
fmt.Printf("User2 final balance: %s XRP\n", finalUser2Balance)
fmt.Printf("Receiver final balance: %s XRP\n", finalReceiverBalance)
}
Loading