1

I am struggling to set a Trustline.

  1. Create account
  2. Send Funds to New account
  3. Set Trust for a Token
  4. Send the Token. I am having a big problem trying to get step 3 working, many online examples are using the old method and converting them has its own issues. I created a Function as follows:
func TrustToken(issuedAsset txnbuild.Asset, limit string, targetAccount keypair.Full, sourceAccount keypair.Full) {
    client, _ := connectStellar()

    allowTrust := txnbuild.SetTrustLineFlags{
        Trustor:  targetAccount.Address(),
        Asset:    issuedAsset,
        SetFlags: []txnbuild.TrustLineFlag{txnbuild.TrustLineAuthorized},
    }

    kp, _ := keypair.Parse(sourceAccount.Seed())
    ar := horizonclient.AccountRequest{AccountID: kp.Address()}
    account, err := client.AccountDetail(ar)
    if lib.CheckErr(err) {
        panic(err)
    }

    tx, err := txnbuild.NewTransaction(
        txnbuild.TransactionParams{
            SourceAccount:        &account,
            IncrementSequenceNum: true,
            Operations:           []txnbuild.Operation{&allowTrust},
            Preconditions:        txnbuild.Preconditions{TimeBounds: txnbuild.NewInfiniteTimeout()},
            BaseFee:              txnbuild.MinBaseFee,
        },
    )
    if lib.CheckErr(err) {panic(err)}

    // Sign it.
    txeBase64 := ""
    if mainNetwork() {
        signedTX, _ := tx.Sign(network.PublicNetworkPassphrase, &targetAccount)
        txeBase64, _ = signedTX.Base64()
    } else {
        signedTX, _ := tx.Sign(network.TestNetworkPassphrase, &targetAccount)
        txeBase64, _ = signedTX.Base64()
    }

    resp, errSubmit := client.SubmitTransactionXDR(txeBase64)
    if lib.CheckErr(errSubmit) {
        hError := errSubmit.(*horizonclient.Error)
        lib.Error("Error submitting transaction:", hError.Problem)
    }

}

I removed a few debug statements and noise to simplify this function. but I am getting the error:horizon error: "Transaction Failed" (tx_bad_auth) I really would like to fin a working example somewhere, Google has evaded my searches. and any guidance of finger point will be very apprecated.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.