HomeArtTechHackBlockchain
ONLINE ·
Index
/
Blockchain101
/
Article

มาสร้าง Stellar Account ด้วย Go SDK กัน

Operator
Khomkrid Lerdprasert
Filed
November 07, 2021
Channel
Blockchain101
Read
~1 min
มาสร้าง Stellar Account ด้วย Go SDK กัน

ลองสร้าง Stellar Account และรับ 1000 XLM จาก Testnet ดู ด้วย Go SDK

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() {
pair, _ := keypair.Parse("secret key")
addr := pair.Address()
client := horizonclient.DefaultTestNetClient
accountRequest := horizonclient.AccountRequest{AccountID: addr}
account1, err := client.AccountDetail(accountRequest)
if err != nil {
log.Fatalln(err)
}
des, _ := keypair.Random()
createAccountOp := txnbuild.CreateAccount{
Destination: des.Address(),
Amount: "1000",
}
txParams := txnbuild.TransactionParams{
SourceAccount: &account1,
IncrementSequenceNum: true,
Operations: []txnbuild.Operation{&createAccountOp},
BaseFee: txnbuild.MinBaseFee,
Timebounds: txnbuild.NewTimeout(300),
}
tx, _ := txnbuild.NewTransaction(txParams)
signedTx, err := tx.Sign(network.TestNetworkPassphrase, pair.(*keypair.Full))
if err != nil {
log.Fatalln(err)
}
txeBase64, err := signedTx.Base64()
if err != nil {
log.Fatalln(err)
}
log.Println("Transaction base64: ", txeBase64)
resp, err := client.SubmitTransactionXDR(txeBase64)
if err != nil {
hError := err.(*horizonclient.Error)
log.Fatal("Error submitting transaction:", hError.Problem)
}
log.Println("Transaction response: ", resp)
}

◎ Tags

##blockchain##stellar##จดบันทึก
Khomkrid Lerdprasert
Operator

Khomkrid Lerdprasert

Technical Lead — building AI-powered platforms, omni-channel chat systems, and telemedicine solutions with Go, Next.js & clean architecture. 20+ years shipping software from crypto wallets to e-learning systems. Bangkok-based. Writes code late at night, brews beer on weekends.

GithubInstagram
Previous · transmission
ใช้ Go Create Transaction เพื่อโอนเงินใน stellar
Next · transmission
บันทึก การทำ Cronjob ง่ายๆ บน go fiber
Metadata
Channel
Blockchain101
Filed
November 07, 2021
Read
~1 min
Language
TH / EN
Transmit

Related

ใช้ Go สร้าง account แบบ Multi Sign
Khomkrid Lerdprasert
November 07, 2021
1 min
aofiee.dev
signal / noise / code · craft
© 2019 – 2026, Khomkrid Lerdprasert.
All transmissions logged.
No newsletter. No profiling. Cookies require consent.
PGP · 7F3D 2024 A21E B584 · 0x7F3D
Channels
  • Art & Culture
  • Technology
  • Hack 101
  • Blockchain 101
  • Archive / All posts
— END OF TRANSMISSION —
// powered by curiosity, coffee, & wuxia
BKK · 13°45′N · 100°30′E