HomeArtTechHackBlockchain

ใช้ Go Create Transaction เพื่อโอนเงินใน stellar

By Khomkrid Lerdprasert
Published in Blockchain101
November 07, 2021
1 min read
ใช้ Go Create Transaction เพื่อโอนเงินใน stellar
package main
import (
"log"
"github.com/stellar/go/clients/horizonclient"
"github.com/stellar/go/keypair"
"github.com/stellar/go/network"
"github.com/stellar/go/txnbuild"
)
func main() {
source := "secret key"
destination := "address key"
client := horizonclient.DefaultTestNetClient
destAccountRequest := horizonclient.AccountRequest{AccountID: destination}
destinationAccount, err := client.AccountDetail(destAccountRequest)
if err != nil {
panic(err)
}
sourceKeyPair := keypair.MustParseFull(source)
sourceAccountRequest := horizonclient.AccountRequest{AccountID: sourceKeyPair.Address()}
sourceAccount, err := client.AccountDetail(sourceAccountRequest)
if err != nil {
panic(err)
}
tx, err := txnbuild.NewTransaction(
txnbuild.TransactionParams{
SourceAccount: &sourceAccount,
IncrementSequenceNum: true,
BaseFee: txnbuild.MinBaseFee,
Timebounds: txnbuild.NewInfiniteTimeout(),
Operations: []txnbuild.Operation{
&txnbuild.Payment{
Destination: destinationAccount.AccountID,
Amount: "10",
Asset: txnbuild.NativeAsset{},
},
},
},
)
if err != nil {
panic(err)
}
tx, err = tx.Sign(network.TestNetworkPassphrase, sourceKeyPair)
if err != nil {
panic(err)
}
resp, err := horizonclient.DefaultTestNetClient.SubmitTransaction(tx)
if err != nil {
panic(err)
}
log.Println("Successful Transaction:")
log.Println("Ledger:", resp.Ledger)
log.Println("Hash:", resp.Hash)
}

Tags

#blockchain#stellar#จดบันทึก

Share

Previous Article
ใช้ Go Create Transaction และแนบ key value เพื่อโอนเงินใน stellar
Khomkrid Lerdprasert

Khomkrid Lerdprasert

Full Stack Life

Related Posts

ใช้ Go สร้าง account แบบ Multi Sign
November 07, 2021
1 min
© 2024, All Rights Reserved.
Powered By

Quick Links

Author

Social Media