sdk "github.com/stellar/go/clients/horizonclient"
"github.com/stellar/go/keypair"
"github.com/stellar/go/network"
"github.com/stellar/go/txnbuild"
"github.com/stellar/go/xdr"
client := sdk.DefaultTestNetClient
// Suppose that these accounts exist and are funded accordingly:
A := "SCZANGBA5YHTNYVVV4C3U252E2B6P6F5T3U6MM63WBSBZATAQI3EBTQ4"
B := "GA2C5RFPE6GCKMY3US5PAB6UZLKIGSPIUKSLRB6Q723BM2OARMDUYEJ5"
// Load the corresponding account for A.
aKeys := keypair.MustParseFull(A)
aAccount, err := client.AccountDetail(sdk.AccountRequest{
AccountID: aKeys.Address(),
// Create a claimable balance with our two above-described conditions.
soon := time.Now().Add(time.Second * 60)
bCanClaim := txnbuild.BeforeRelativeTimePredicate(60)
aCanReclaim := txnbuild.NotPredicate(
txnbuild.BeforeAbsoluteTimePredicate(soon.Unix()),
claimants := []txnbuild.Claimant{
txnbuild.NewClaimant(B, &bCanClaim),
txnbuild.NewClaimant(aKeys.Address(), &aCanReclaim),
// Create the operation and submit it in a transaction.
claimableBalanceEntry := txnbuild.CreateClaimableBalance{
Asset: txnbuild.NativeAsset{},
// Build, sign, and submit the transaction
tx, err := txnbuild.NewTransaction(
txnbuild.TransactionParams{
SourceAccount: &aAccount,
IncrementSequenceNum: true,
BaseFee: txnbuild.MinBaseFee,
// Use a real timeout in production!
Timebounds: txnbuild.NewInfiniteTimeout(),
Operations: []txnbuild.Operation{&claimableBalanceEntry},
tx, err = tx.Sign(network.TestNetworkPassphrase, aKeys)
txResp, err := client.SubmitTransaction(tx)
fmt.Println("Claimable balance created!")