3

How can I send a transaction with a vector of tuples like Option<Vec<(T::AccountId, u8)>> from frontend (react)? What about None and other types js don't have? Is there any site I can look for?

1 Answer 1

9

There are 2 questions here -

  • None as found in an Option
  • Tuple types

In the JS world you can do the following -

// signature of this extrinsic is value: Option<(T::AccountId, u8)>
// send None through - mapped from null
await api.tx.someWhere.something(null)

// send a Tuple value through
await api.tx.someWhere.something(['1Test...', 5])

So Tuple values appear is a JS array with the correct number of elements.

To expand this into your signature type posted above, i.e. an Option of a Vec of Tuples -

// signature of this extrinsic is value: Option<Vec<(T::AccountId, u8)>>
// send None through - mapped from null
await api.tx.someWhere.something(null)

// send a Vec<Tuple> value through (2 values)
await api.tx.someWhere.something([['1Test...', 5], ['1Test...', 6]])

The same would apply to eg. .query.* if you need to specify a Tuple.

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.