Reposting from the Sui subreddit: Original Post
Hi Friends!
Suppose I want to create smart-contract which mints tokens and transfers them to the requested addresses. Actually I created one which accepts single destination wallet address. So if I want to deliver tokens to 10 addresses I need to call it 10 times.
Is there a way to pass a list / array of values as an argument of entry function? I can’t immediately find any docs on this (and how to call it say from SUI CLI, if it is possible). So that my smart-contract may accept a list of wallets and spread tokens to them according to some logic (living inside this contract also).
As workarounds, I guess i can pass them as single string, separated with spaces. Or perhaps json (as single string also), though my skills in Move currently are not so great to do it easily). Or list of arguments can be stored on-chain. But I would like to know if there is more straightforward way. Thanks!
Can anyone here help our friend RodionGork out?
User u/kristaki90 later followed up with this reply:
Hi u/RodionGork
Yes it is possible to pass an array as an argument into an entry function. Here is an example of how you can do it:// You will need to change the entry function to accept an array of addresses. howto::how_to_array { use sui::tx_context::{Self, TxContext}; use sui::object::{Self, UID}; use sui::transfer; use std::string::{Self,String}; struct VecTest has key, store{ id: UID, myvec: vector<address> } public entry fun test_vec(v: vector<address>, ctx: &mut TxContext) { transfer::transfer( VecTest { id: object::new(ctx), myvec: v }, tx_context::sender(ctx)) } }
And then you can call it through cli like this:
sui client call \ --package 0x0a38fd5a7da36606fea72c112e0134f12abb2b6d3a545bacd21f8dbbe3f8fge6 \ --module how_to_array \ --function test_vec \ --args '[0xc6742425e89f7e4ade7de9cf20f2867b0978379f7d23a5bd7e6833b9422483af, 0xc6742425e89f7e4ade7de9cf20f2867b0978379f7d23a5bd7e6833b9422483af]' \ --gas-budget 1000 1