Skip to content

Instantly share code, notes, and snippets.

@abuiles
Created August 10, 2020 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abuiles/03f2395db530314f566519e39b1dabce to your computer and use it in GitHub Desktop.
Save abuiles/03f2395db530314f566519e39b1dabce to your computer and use it in GitHub Desktop.
Sample cap33 on standalone
package main
import (
"log"
"github.com/stellar/go/clients/horizonclient"
"github.com/stellar/go/keypair"
"github.com/stellar/go/txnbuild"
)
// var Passphrase = network.TestNetworkPassphrase
var Passphrase = "Standalone Network ; February 2017"
func main() {
// Make a keypair for a known account from a secret seed
kp := keypair.Master(Passphrase)
// kp, _ := keypair.Parse("SC4JDII6OYNXAY3ICRACJXCCOHISSZEP3WQ4TXIL7DXRHGO7ZOTUG735")
// Get the current state of the account from the network
client := horizonclient.DefaultTestNetClient
client.HorizonURL = "https://url.ngrok.io"
ar := horizonclient.AccountRequest{AccountID: kp.Address()}
sourceAccount, err := client.AccountDetail(ar)
if err != nil {
log.Fatalln(err)
}
// Build an operation to create and fund a new account
// Public Key GCFEQ7DVT2DXKFKHGFWHMCSRYMFDGUADPNF7KFPAE3C2P7YUQBMH4DG2
// Secret Key SC4JDII6OYNXAY3ICRACJXCCOHISSZEP3WQ4TXIL7DXRHGO7ZOTUG735
// Public Key GDP5EHRW3RXYQFMGWM3AXDIO34NHU7VS3DEGZNLQRWAES2FQ23DTNL7Y
// Secret Key SAYYG4Y33MR2NEN26L7TAPGWYNYGKCXRZEYCOT76ZDK7K67R5LB6HPKY
//
// Public Key GBE4URUXRVVW2TTOCSJCTAZ3SQNXO24A2QM6XD7E4Y2JL63OP6HNRCNV
// Secret Key SBSP6KR3ZBJWH43V2Y4IUKUIBBSHCUCTKYVLDLOWV2IMP6MIRCTUPMGG
//
np, _ := keypair.Parse("SC4JDII6OYNXAY3ICRACJXCCOHISSZEP3WQ4TXIL7DXRHGO7ZOTUG735")
ops := []txnbuild.Operation{
&txnbuild.BeginSponsoringFutureReserves{
SponsoredID: "GCFEQ7DVT2DXKFKHGFWHMCSRYMFDGUADPNF7KFPAE3C2P7YUQBMH4DG2",
},
&txnbuild.CreateAccount{
Destination: "GCFEQ7DVT2DXKFKHGFWHMCSRYMFDGUADPNF7KFPAE3C2P7YUQBMH4DG2",
Amount: "0",
},
&txnbuild.EndSponsoringFutureReserves{
SourceAccount: &txnbuild.SimpleAccount{
AccountID: "GCFEQ7DVT2DXKFKHGFWHMCSRYMFDGUADPNF7KFPAE3C2P7YUQBMH4DG2",
},
},
// &txnbuild.BeginSponsoringFutureReserves{
// SponsoredID: "GCFEQ7DVT2DXKFKHGFWHMCSRYMFDGUADPNF7KFPAE3C2P7YUQBMH4DG2",
// },
// &txnbuild.CreateAccount{
// Destination: "GCFEQ7DVT2DXKFKHGFWHMCSRYMFDGUADPNF7KFPAE3C2P7YUQBMH4DG2",
// Amount: "0",
// },
// &txnbuild.EndSponsoringFutureReserves{},
// &txnbuild.CreateClaimableBalance{
// Destinations: []string{
// "GCFEQ7DVT2DXKFKHGFWHMCSRYMFDGUADPNF7KFPAE3C2P7YUQBMH4DG2",
// "GDP5EHRW3RXYQFMGWM3AXDIO34NHU7VS3DEGZNLQRWAES2FQ23DTNL7Y",
// },
// Amount: "20",
// Asset: txnbuild.NativeAsset{},
// },
// &txnbuild.CreateClaimableBalance{
// Destinations: []string{
// "GCFEQ7DVT2DXKFKHGFWHMCSRYMFDGUADPNF7KFPAE3C2P7YUQBMH4DG2",
// },
// Amount: "20",
// Asset: txnbuild.NativeAsset{},
// },
// &txnbuild.ClaimClaimableBalance{
// BalanceID: "AAAAANq8UyS+WzhAw8kYOZzeDNw7AWjGKBUdq8DswgRHPXF2",
// },
}
// Construct the transaction that holds the operations to execute on the network
tx, err := txnbuild.NewTransaction(
txnbuild.TransactionParams{
SourceAccount: &sourceAccount,
IncrementSequenceNum: true,
Operations: ops,
BaseFee: txnbuild.MinBaseFee * 4,
Timebounds: txnbuild.NewTimeout(300),
},
)
if err != nil {
log.Fatalln(err)
}
// Sign the transaction
tx, err = tx.Sign(Passphrase, kp.(*keypair.Full))
if err != nil {
log.Fatalln(err)
}
tx, err = tx.Sign(Passphrase, np.(*keypair.Full))
if err != nil {
log.Fatalln(err)
}
// Get the base 64 encoded transaction envelope
txe, err := tx.Base64()
if err != nil {
log.Fatalln(err)
}
// fmt.Println(txe)
// Send the transaction to the network
_, err = client.SubmitTransactionXDR(txe)
if err != nil {
log.Fatalln(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment