0

I have following action in my smartcontract:

ACTION uploadfile1 (name creator, vector<uint8_t> content, string filename)

I'm trying to push action from my Swift application using following code:

struct uploadFile: Codable {
    var creator: EosioName
    var content: [Int8]
    var filename: String
}

    let testArr = Array(repeating: Int8(20), count: 10)
    let data = uploadFile(creator: try! EosioName("tibackbone"),
                          content: testArr,
                          filename: theFileName)

    rpcProvider = EosioRpcProvider(endpoint: endpoint)
    guard let rpcProvider = rpcProvider else {
        print("ERROR: No RPC provider found.")
        return
    }

    let serializationProvider = EosioAbieosSerializationProvider()
    let signatureProvider = try! EosioSoftkeySignatureProvider(privateKeys: privateKeys)
    transactionFactory = EosioTransactionFactory(
        rpcProvider: rpcProvider,
        signatureProvider: signatureProvider,
        serializationProvider: serializationProvider
    )
    
    let transaction = transactionFactory?.newTransaction()
    let action = try! EosioTransaction.Action(
        account: EosioName(accountName),
        name: EosioName("uploadfile1"),
        authorization: [EosioTransaction.Action.Authorization(
            actor: EosioName(accountName),
            permission: EosioName("active"))
        ],
        data: data
    )

    transaction?.add(action: action)

    transaction?.signAndBroadcast { result in
        switch result {
        case .failure (let error):
            print("*** TRANSACTION ERROR")
            print("---- ERROR SIGNING OR BROADCASTING TRANSACTION")
            print(error)
            print(error.reason)
        case .success (let info):
            if let transactionId = transaction?.transactionId {
                print("Transaction ID \(transactionId)")
        default: break
        }
    }

When i'm running this code i'm receiving following error:

*** TRANSACTION ERROR ---- ERROR SIGNING OR BROADCASTING TRANSACTION Error was encountered in SerializationProvider. Unable to pack json to bin. Expected string

Can anyone suggest me where i'm wrong and what i'm missing.

Thanks to everyone in advance!

3
  • I'm not really familiar with Swift but I'd guess it's because uploadFile.content is [Int8] not [uint8]. Or it is the conversion between an array and a vector that's breaking things.
    – cmadh
    Oct 24, 2021 at 1:09
  • I tried with UInt8, but the result is the same.
    – Boni
    Oct 25, 2021 at 3:49
  • Some more observations - if I try to pass array of strings, everything goes fine, but all other types of data gives the mentioned above error.
    – Boni
    Oct 25, 2021 at 10:45

0

Your Answer

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

Browse other questions tagged or ask your own question.