1

I'm using the iOS SDK to attempt to submit a testnet transaction, but it fails with error 6, which I believe is BAD_AUTH, too few valid signatures/ wrong network.

Here is my code:

static func sendPayment(accountId: String, amount: Decimal, completion: @escaping (Bool) -> Void) {

    guard let sourceKeyPair = try? KeyPair(secretSeed: KeychainHelper.privateSeed) else {
        DispatchQueue.main.async {
            print("NO SOURCE KEYPAIR")
            completion(false)
        }
        return
    }

    let issuerID = Assets.AssetType.ABC.issuerAccountID

    guard let issuerKeyPair = try? KeyPair(accountId: issuerID) else {
        print("NO ISSUER KEYPAIR")
        DispatchQueue.main.async {
            completion(false)
        }
        return
    }

    guard  let destinationKeyPair = try? KeyPair(publicKey: PublicKey.init(accountId: accountId), privateKey: nil) else {
        DispatchQueue.main.async {
            completion(false)
        }
        return
    }

    Stellar.sdk.accounts.getAccountDetails(accountId: sourceKeyPair.accountId) { (response) -> (Void) in

        switch response {
        case .success(let accountResponse):
            do {
                let asset = Asset(type: AssetType.ASSET_TYPE_CREDIT_ALPHANUM4, code: "ABC", issuer: issuerKeyPair)!

                let paymentOperation = PaymentOperation(sourceAccount: sourceKeyPair,
                                                        destination: destinationKeyPair,
                                                        asset: asset,
                                                        amount: amount)

                let transaction = try Transaction(sourceAccount: accountResponse,
                                                  operations: [paymentOperation],
                                                  memo: nil,
                                                  timeBounds:nil)

                try transaction.sign(keyPair: sourceKeyPair, network: Stellar.network)

                try Stellar.sdk.transactions.submitTransaction(transaction: transaction) { (response) -> (Void) in
                    switch response {
                    case .success(_):
                        DispatchQueue.main.async {
                            completion(true)
                        }
                    case .failure(let error):
                        StellarSDKLog.printHorizonRequestErrorMessage(tag:"Post Payment Error", horizonRequestError:error)
                        DispatchQueue.main.async {
                            completion(false)
                        }
                    }
                }
            }
            catch {
                DispatchQueue.main.async {
                    print("FAILED TO GET ACCOUNT")
                    completion(false)
                }
            }
        case .failure(let error):
            StellarSDKLog.printHorizonRequestErrorMessage(tag:"Post Payment Error", horizonRequestError:error)
            DispatchQueue.main.async {
                completion(false)
            }
        }
    }
}

This is the error:

Post Payment Error: Horizon request error of type request failed with message: The operation couldn’t be completed. (stellarsdk.XDRDecoder.Error error 6.)

I swear this worked a week ago, so I'm kinda stumped here. Any help would be appreciated.

Your Answer

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

Browse other questions tagged or ask your own question.