The best way
The best way is quite an objective term.
The most cost effective way is definitely to execute them all in one loop (option 1), although there will be a limit to how many addresses you can perform at once (you'll probably need to do 10 batches of 100 addresses each).
Option 2 may indirectly cost you less in gas, but someone still has to pay the gas, and since they will be (presumably) executing one by one, the overall gas cost will be more, but since you won't be paying it, maybe that's better for you?
A slightly better implementation:
function distributeToken(address[] addresses, uint256 _value) onlyOwner {
uint total = _value * addresses.length;
require(total/_value == addresses.length); // Overflow check
require(balances[owner] >= total); // Underflow check
balances[owner] -= total;
for (uint i = 0; i < addresses.length; i++) {
balances[addresses[i]] += _value;
require(balances[addresses[i]] >= _value); // Overflow check
Transfer(owner, addresses[i], _value);
}
}
Gas estimations:
For single calls to a typical transfer()
function, it's the same cost per call, which means that for each address you'll be paying 23,500 gas.
However when you perform a bulk update instead, you save the overhead of the invocation cost and just have to pay the cost of the loop and storage etc. After a base cost of 27,947 gas, each address only costs an extra 9,703 gas.
┌─────┬────────────┬─────────────────┐
│ # │ transfer │ distributeToken │
├─────┼────────────┼─────────────────┤
│ 1 │ 23,500 │ 37,650 │
│ 2 │ 47,000 │ 47,353 │
│ 3 │ 70,500 │ 57,056 │
│ 10 │ 235,000 │ 124,977 │
│ 50 │ 1,175,000 │ 513,097 │
│ 500 │ 11,750,000 │ 4,879,447 │
└─────┴────────────┴─────────────────┘
That means after 2 addresses it's cheaper.
For 8 Mgas (maximum for a single call), you could do around 821 addresses:
27,947 base call gas + 9,703 gas/address * 821 addresses = 7,994,110 gas
Best Answer
You can't really "move" a contract. Once a contract is deployed, it stays there forever (unless it has implemented
selfdestruct
). So you simply need to deploy the same contract with the same source code again in the new blockchain.The differences between the blockchains are subtle. Mostly:
Different governance / (de)centralization models. Ethereum is fully decentralized, BSC is partially decentralized (dPoS)
Different use base. Ethereum has more users probably
Different services. In theory, they could have almost exactly the same services, but most projects don't launch their products in multiple blockchains (at least immediately)