I constructed the Stellar private network on my Mac following https://www.stellar.org/developers/stellar-core/software/admin.html#starting-a-new-network with postgres and horizon server. I know what the root account and its secret seed of my Stellar node is.
I tried creating a new account with Stellar go SDK. From the information of https://www.stellar.org/developers/go/reference/examples.html and https://github.com/stellar/go/blob/master/services/friendbot/internal/friendbot.go (Pay method), I made a simple client for account creation.
package main
import (
"log"
"github.com/stellar/go/keypair"
b "github.com/stellar/go/build"
"github.com/stellar/go/clients/horizon"
"fmt"
"net/http"
)
func main() {
pair, err := keypair.Random()
if err != nil {
log.Fatal(err)
}
log.Println(pair.Seed())
log.Println(pair.Address())
to := pair.Address()
from := "SDHOAMBNLGCE2MV5ZKIVZAQD3VCLGP53P3OBSBI6UN5L5XZI5TKHFQL4" // root seed at --newdb time
var PrivateNetClient = &horizon.Client{
URL: "http://localhost:8000",
HTTP: http.DefaultClient,
}
tx, err := b.Transaction(
b.SourceAccount{AddressOrSeed: from},
b.AutoSequence{SequenceProvider: PrivateNetClient},
//b.Sequence{Sequence: 1},
b.TestNetwork,
b.CreateAccount(
b.Destination{AddressOrSeed: to},
b.NativeAmount{Amount: "1000.00"},
),
)
if err != nil {
panic(err)
}
txe, err := tx.Sign(from)
if err != nil {
panic(err)
}
txeB64, err := txe.Base64()
if err != nil {
panic(err)
}
fmt.Printf("tx base64: %s", txeB64)
resp, err := PrivateNetClient.SubmitTransaction(txeB64)
if err != nil {
switch e := err.(type) {
case *horizon.Error:
fmt.Println("err type=" + e.Problem.Type)
fmt.Println("err detailed=" + e.Problem.Detail)
fmt.Println("err extras=" + string(e.Problem.Extras["result_codes"]))
}
panic(err)
}
fmt.Println("transaction posted in ledger:", resp.Ledger)
}
Making the base64 string of CreateAccount operation XDR is so far so good, but the result of SubmitTransaction is always 400(Bad Request Error) with 'tx_bad_seq'.
stellar-core and horizon are running with debug log level but there's no noticeable log.
How can I resolve this? (The message below is my client log.)
2018/02/11 10:38:27 SD7AK2XVUZPVCNTJEKIG5ZZ4CXYXRMMB55YBAMAWCPTI3T3T7WYIBEKN
2018/02/11 10:38:27 GDTD7B3NDD7YEDPPP2MWGTX2K5DXGTDECUYSDWFTVBIMMD7O5SBUFE5M
tx base64: AAAAAGL8HQvQkbK2HA3WVjRrKmjX00fG8sLI7m0ERwJW/AX3AAAAZAAAAAAAAAABAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAA5j+HbRj/gg3vfpljTvpXR3NMZBUxIdizqFDGD+7sg0IAAAACVAvkAAAAAAAAAAABVvwF9wAAAEA8s/KhXtXz77Q5wu+lj/z/OgLE25CahIJWUB12+9LR6g5BiG/CBB9e143VTUoivu6yF8i8MXRuCyIF2TzCsxYLerr type=https://stellar.org/horizon-errors/transaction_failed
err detailed=The transaction failed when submitted to the stellar network. The `extras.result_codes` field on this response contains further details. Descriptions of each code can be found at: https://www.stellar.org/developers/learn/concepts/list-of-operations.html
err extras={
"transaction": "tx_bad_seq"
}
panic: Horizon error: "Transaction Failed". Check horizon.Error.Problem for more information.
goroutine 1 [running]:
main.main()
/Users/eugene/project/ylabs/stellar_client/new_account_with_sdk.go:63 +0xb5e