0

How can i pack on taquito side params so that they match what i would get in smartpy with sp.pack? Say i have params two ints and a string: 1, 3, "something" What do i need to do in taquito to get same bytes as i would with sp.pack(1, 3, "something").

We have a pay-gas-by-proxy system so we need this in order to compute sig of params on frontend side and then check it in smartpy.

1

In SmartyPy -

record = sp.record(x=1,y=3,z="something")
bytes = sp.pack(record)
pprint(vars(bytes))

gives something like -

{'__initialized': True,
 '_f': 'pack',
 '_l': [(record ("my_contract.py" 6) (x (literal (intOrNat 1) ("my_contract.py" 6))) (y (literal (intOrNat 3) ("my_contract.py" 6))) (z (literal (string "something") ("my_contract.py" 6)))),
        <smartpy.LineNo object at 0x103593340>],
 'attributes': {},
 'onUpdateHandlers': [],
 'opens': {}}

In taquito Michel codec package we have pack and packDataBytes, see example below -

const data: MichelsonData = {
    prim: 'Pair', args: [{ int: '1' }, { int: '3' }, { string:"something" }]
};

const typ: MichelsonType = {
  prim: 'pair', args: [{ prim: 'int' }, { prim: 'int' }, { prim:"string" }]
};

const packedBytes = packDataBytes(data, typ);
// { bytes: "0507070707000100030100000009736f6d657468696e67" }

both give you different format in terms of bytes. I would like to understand your needs and how you want to equate taquito bytes representation with SmartPy's representation.

Kunal

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.