You're trying to make the contract send funds it doesn't have. It needs ether to draw from. The balance would start at 0, so you need to add a function() payable{}
and send some ether to work with.
I've marked a section of the code *** unsafe ***
to avoid misunderstanding. There are deeper concerns about handling money this way. A good next step is to check the success/fail of the send()
operation and then respond differently. I have it emitting a failure message or a success message.
I added some event emitters so you can see what's going on.
Hope it helps.
contract project{
address public user;
bytes32[10] name;
address[10] customer;
uint public i=0;
event LogDep (address sender, uint amount, uint balance);
event LogSent(address recipient, uint amount, uint balance);
event LogErr (address recipient, uint amount, uint balance);
function project(){
user=msg.sender;
}
function depositFunds() public payable returns(bool success) {
LogDep(msg.sender, msg.value, this.balance);
return true;
}
function add(bytes32 _name){
name[i]=_name;
customer[i]=msg.sender;
i++;
}
function get_address() constant returns(address[10]){
return customer;
}
function reward() {
for(uint i=0;i<10;i++)
{
// *** unsafe pattern ***
if(customer[i].send(1)) {
LogSent(customer[i], 1, this.balance);
} else {
LogErr(customer[i], 1, this.balance);
}
}
}
}
Here it is in Remix to show it working.
If you haven't seen Remix before, go here https://ethereum.github.io/browser-solidity and just paste the code into the compiler. You can interact with the contract functions.
Step 1: Create the contract
Step 2: Send the contract some funds
10 wei is just enough to send 1 to all 10 customers. If you send less, you'll start seeing failed sends in Step 3.
Step 3: send txn to reward()
Be sure to NOT send wei/eth this time, because this function isn't payable.