HomeArtTechHackBlockchain

ใช้ Go สร้าง account แบบ Multi Sign

By Khomkrid Lerdprasert
Published in Blockchain101
November 07, 2021
1 min read
ใช้ Go สร้าง account แบบ Multi Sign
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"
destination := "address"
sign1Address := "address"
sign1Key := "secret"
sign2Address := "GDFOEXX3UY3JMPUR3T6YH2VSVB5QJCDQIPPAD3CVCT56ZVVIOKUWWGA2"
sign3Address := "GC4ABHKWEFMLO77C33VDQWHSIIPNZ3JKMEKPKCRLOVCRWWZQQ7LHK7HT"
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.SetOptions{
Signer: &txnbuild.Signer{
Address: sign1Address,
Weight: 1,
},
},
&txnbuild.SetOptions{
Signer: &txnbuild.Signer{
Address: sign2Address,
Weight: 1,
},
},
&txnbuild.SetOptions{
Signer: &txnbuild.Signer{
Address: sign3Address,
Weight: 1,
},
},
&txnbuild.Payment{
Destination: destinationAccount.AccountID,
Amount: "10",
Asset: txnbuild.NativeAsset{},
},
},
},
)
if err != nil {
panic(err)
}
tx, err = tx.Sign(network.TestNetworkPassphrase, keypair.MustParseFull(sign1Key))
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
ใช้ tendermint cosmos สร้าง Blockchain สำหรับ การทำ Beer Craft
Khomkrid Lerdprasert

Khomkrid Lerdprasert

Full Stack Life

Related Posts

ใช้ Go Create Transaction เพื่อโอนเงินใน stellar
November 07, 2021
1 min
© 2024, All Rights Reserved.
Powered By

Quick Links

Author

Social Media