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 https://gitlab.com/jklepatch/eattheblocks-pro/-/tree/master/dapp-30/day7-split-payment/frontend/start/public

and just see the empty initApp function.

   const amount = e.target.elements[1].value
  .split(',')
  .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.