Created
August 7, 2020 23:21
-
-
Save abuiles/adfbeef7d85926c1bde1f938c8cd1381 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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://6d09c563c0cd.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 | |
// | |
// op := txnbuild.CreateAccount{ | |
// Destination: "GDP5EHRW3RXYQFMGWM3AXDIO34NHU7VS3DEGZNLQRWAES2FQ23DTNL7Y", | |
// Amount: "100", | |
// } | |
op := txnbuild.CreateClaimableBalance{ | |
Destinations: []string{ | |
"GCFEQ7DVT2DXKFKHGFWHMCSRYMFDGUADPNF7KFPAE3C2P7YUQBMH4DG2", | |
"GDP5EHRW3RXYQFMGWM3AXDIO34NHU7VS3DEGZNLQRWAES2FQ23DTNL7Y", | |
"GBE4URUXRVVW2TTOCSJCTAZ3SQNXO24A2QM6XD7E4Y2JL63OP6HNRCNV", | |
}, | |
Amount: "20", | |
Asset: txnbuild.NativeAsset{}, | |
} | |
// op := txnbuild.ClaimClaimableBalance{ | |
// BalanceID: "AAAAABchk5v+5pIqF2GPoFbSQqxQBBVbtrLuY78jgs0btHFy", | |
// } | |
// Construct the transaction that holds the operations to execute on the network | |
tx, err := txnbuild.NewTransaction( | |
txnbuild.TransactionParams{ | |
SourceAccount: &sourceAccount, | |
IncrementSequenceNum: true, | |
Operations: []txnbuild.Operation{&op}, | |
BaseFee: txnbuild.MinBaseFee, | |
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) | |
} | |
// 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