Let's say there's a button in html that can claim winnings.
<button type="submit" (click)="claimWinnigs()">Claim Winnings</button>
A user with account address 0xf17...b732 claimed winnings by clicking the button. What I want here is I want that user to be able to withdraw eth from the contract address (0x8f...b90f). Metamask is the tool I'm using.
simplified solidity:
mapping(address => uint256) public balanceOf
function claimWinnings() returns (bool) {
balanceOf[msg.sender] = 20
withdraw();
return true;
}
function withdraw() public {
uint256 balance = balanceOf[msg.sender];
balanceOf[msg.sender] -= balance;
msg.sender.transfer(balance);
LogWithdrawal(msg.sender, balance);
}
Below is my angular web3 code:
claimWinnings(): Promise<any> {
return this.TestContract.deployed().then((instance) => {
return claimWinnings({
from: contractAddress,
gas: 1000000
});
})
.then((value) => {
return value;
})
.catch((e) => {
console.log(e);
});
}
But when I execute this, I get an error
Unknown address - unable to sign transaction for this address: "0x8f...b90f"
I'm testing with Ganache fyi.
What am I doing wrong here? and how can the user receive ether from the contract?