2

I initialized a vector in ink smart contract like this:

bidders: Vec<AccountId>

What is the best way to iterate over the vector?

1 Answer 1

2

You can see examples in the docs: ink_prelude::vec::Vec

for bidder in &bidders {
    // do whatever with the AccountId
}

Vec support indexing Vectors also support indexing if you know where is the element you want to get: println!("{}", bidders[1]);

And iterator (See docs):

let mut iterator = bidders.iter();

If you want to bound the length of a Vec in ink!, you can check this previous StackExchange response: BoundedVec on ink!

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.