2

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
1

The only thing that comes to my mind is that your node actually synced with the publicly available test network and applied the history. That's why the master account's (GBRPYHIL2CI3FNQ4BXLFMNDLFJUNPU2HY3ZMFSHONUCEOASW7QC7OX2H) sequence number is higher than 1 and you're getting tx_bad_seq.

If you want to create a fully isolated network change network_passphrase in stellar core configuration and create a new Network object in Go SDK with such passphrase.

  • It’s the sole node in the private network. Actually it wasn’t the sequence problem, but I think horizon has a problem that it processes other types of error as tx_bad_seq. – Eugene Chung Feb 13 '18 at 0:02
0

I forgot to call ‘stellar-core --forcescp’ before running my core node. After the first CreateAccount request is timed out because the node doesn’t process anything, the next requests are failed with ‘tx_bad_seq’ error. So I misunderstood that it was the sequence problem.

I added the issue below. https://github.com/stellar/stellar-core/issues/1540

  • Please close this question if you've figured out a solution!! Thanks!! – EndingWithAli Mar 5 '18 at 19:29
  • I'm sorry I can't find how to close the question. – Eugene Chung Mar 7 '18 at 2:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.