4

When using cargo contract to call contracts, in all the examples i've seen, its either been AccountId or boolean or integers(u & i). I need to pass a Vec<u8> to my contract function. I've been trying but it all results into errors. Please can you help show me how its done. Thank you!

2 Answers 2

2

Here is how i solved it: I converted all the array elements to an hexadecimal string. You can check out the hex crate e.g [20, 103, 114, 101, 97, 116] = 0x + 146772656174(hex string)

Make sure to add 0x to the string before sending it as a parameter.

 Result Success!
    Reverted false
        Data Tuple(Tuple { ident: Some("Ok"), values: [Seq(Seq { elems: [UInt(20), UInt(103), UInt(114), UInt(101), UInt(97), UInt(116)] })] })
0

As stated here:

Try escaping:

cargo contract instantiate \
       --constructor new \
       --args 3 \[5FKy7RwXBCCACCEPjM5WugkhUd787FjdgieTkdj7TPngJzxN] \
       --suri //Alice \
       --code-hash 0xbc1b42256696c8a4187ec3ed79fc602789fc11287c4c30926f5e31ed8169574e
2
  • Once i add more than one element into the array, i throws errors.
    – Woodfish
    Commented Mar 10, 2023 at 19:46
  • Actually, i'm thinking it's the sclae-encoding that should be submitted, instead of the raw thing
    – Woodfish
    Commented Mar 10, 2023 at 19:49

Your Answer

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

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