0

I am trying to submit a Pair of Bytes in a contract call with Taquito but am receiving an error.

The contract interaction documentation does not go into exactly how to submit a Pair, but it does go into how to access a Map with a Pair as a key.

Based on that I arrived at the following code, but am still receiving an error.

Contract has a single entrypoint, run_test, that accepts a Pair of Bytes, with the Bytes themselves being packed Strings.

This is the method used for packing the String (works fine when just sending Bytes instead of a Pair)

const packer = new MichelCodecPacker()
const packString = async stringData => {
  const packedString = await packer.packData({
    data: {
      string: stringData,
    },
    type: {
      prim: 'string',
    }
  })

  return packedString
}

used in the call

const leftByteData = await packString('Left String')
const rightByteData = await packString('Right String')

contract.methods.run_test(
    { 0: leftByteData.packed, 1: rightByteData.packed }
).send()

Which is accepting the type

TPair(TBytes, TBytes)

The error I receive is

BytesValidationError: [4] Invalid bytes: [object Object] at BytesToken.isValid
// ... verbose stack trace info snipped ...
at Array.map (<anonymous>) {
  value: {
    '0': '05010000000b4c65667420537472696e67',
    '1': '05010000000c526967687420537472696e67'
  },
  token: BytesToken {
    val: { prim: 'bytes' },
    idx: 4,
    fac: [Function: createToken],
    createToken: [Function: createToken]
  }
}

Is it possible to send a Pair as a value in a contract call with Taquito, and if so how do you do it?

1 Answer 1

1

Your code is correct, but you have to use the methodsObject property instead of methods if you want to use a JavaScript object as the parameter of the contract call.
Alternatively, you can split the elements of the pair and pass them separately to the contract call, like this:

contract.methods.run_test(leftByteData.packed, rightByteData.packed).send()

To learn more: https://tezostaquito.io/docs/smartcontracts/#choosing-between-the-methods-or-methodsobject-members-to-interact-with-smart-contracts

1
  • listing them one after the other did the trick! thank you, I will migrate my code to using the methodsObject call
    – 0x10
    Jun 21, 2022 at 9:06

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.

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