EatTheBlocks Forum

Day 7 - Front End - Code Example

Where is the code example that is needed to help accept an array of addresses as input in the frontend for the split payment contract?

I looked in

and just see the empty initApp function.

   const amount =[1].value
  .map(val => parseInt(val));
const total = amount.reduce((sum, val) => sum += val);

Why did you go with this solution for variables const amount and const total ?

Would you need a loop if you were sending payments to multiple addresses at once ?

You need to look in the end folder for the solution.

For amount I wanted to make it simple and cram everything into a single input. For production Dapps you probably want to make one input per address.

There is a big difference between:

  1. sending 2 tx from frontend with web3,

  2. and 1 tx that does 2 payments.

Only 2. guarantees that either 2 payments or they dont. for 1. , the first payment could work but not the second one, or vice versa.