2

I'm attempting to transfer funds from the root account to another account on a private stellar network. When I attempt to run the code below (which is basically copied from the examples), I get an error that says the following when I sign the transaction:

hash tx failed: empty network passphrase

The full code is below, where did I go wrong?

package main

import (
    "fmt"
    "github.com/pkg/errors"
    "log"
    "net/http"

    b "github.com/stellar/go/build"
    "github.com/stellar/go/clients/horizon"
    "github.com/stellar/go/keypair"
)

func main() {
    // Root account seed, found in the startup log
    from := "XXXXXXXXXXXXXXXXXXXXXXXXX"

    pair, err := keypair.Random()
    if err != nil {
        log.Fatal(err)
    }

    // Create a new account keypair
    to := pair.Address()

    client := &horizon.Client{
        URL:  "http://127.0.0.1:8000",
        HTTP: http.DefaultClient,
    }

    tx, herr := b.Transaction(
        b.SourceAccount{AddressOrSeed: from},
        b.DefaultNetwork,
        b.AutoSequence{SequenceProvider: client},
        b.Payment(
            b.Destination{AddressOrSeed: to},
            b.NativeAmount{Amount: "100"},
        ),
    )

    if herr != nil {
        //panic(herr.(horizon.Error).Problem.Type)
        panic(errors.WithStack(herr))
    }

    txe, err := tx.Sign(from)
    if err != nil {
        panic(err)
    }

    txe64, err := txe.Base64()
    if err != nil {
        panic(err)
    }

    fmt.Printf("tx base64: %s", txe64)

    resp, err := horizon.DefaultTestNetClient.SubmitTransaction(txe64)
    if err != nil {
        panic(err)
    }

    fmt.Println("transaction posted in ledger:", resp.Ledger)
}
  • I believe the issue here is in regards to the stellar-core.cfg. It may help if you post that here. What did you set for this: NETWORK_PASSPHRASE="Public Global Stellar Network ; September 2015" – Rob Apr 6 '18 at 17:40
1

It looks like I hadn't set the passphrase in the code. The tx should look like the following:

tx, herr := b.Transaction(
    b.SourceAccount{AddressOrSeed: from},
    b.Network{"Network Passphrase""},
    b.AutoSequence{SequenceProvider: client},
    b.Payment(
        b.Destination{AddressOrSeed: to},
        b.NativeAmount{Amount: "100"},
    ),
)

Notice the change from b.DefaultNetwork to b.Network{"Network Passphrase"}

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.