I have a smart contract that sends x ether to an address. I have an html page that has a form for the address, and the amount to be sent. Theoretically it should interface with the smart contract. Nothing happens when i submit the form. It doesn’t work on remix or ganache. On my form, do i have to specify a form action as i would in html? Would the contract not do that?
The html file is similar to https://github.com/dappuniversity/20_minute_dapp/blob/master/index.html but the forms/variables are changed and all the css and formatting is removed.
my sol
pragma solidity ^0.5.11; contract ReceiveEther { uint256 public count; function () external payable { require(count < 2); count++; } function getBalance() public view returns (uint) { return address(this).balance; } } contract SendEther { function sendViaCall (address payable _to) public payable { (bool sent, bytes memory data) = _to.call.value(msg.value)(""); require (sent, "failed to send ether"); } }
My html
<!DOCTYPE html> <html lang="en"> <body> <h1 >send ___ ether to ___ </h1> <br/> <!-- in html/php i have to say what is executed on form submit (usually a php action). Since the smart contract is doing it, do i need to specify anything here or can i do it down below? --> <form role="form"> <label for="Receiver">Receiver:</label><br> <input type="text" id="receiver" name="receiver" ><br> <label for="lname">amount in eth:</label><br> <input type="text" id="amount" name="amount" > <input type="submit" value="Submit" </form> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script src="js/bootstrap.min.js"></script> <script src="js/web3.min.js"></script> <script> // Starting Web3 if (typeof web3 !== 'undefined') { web3 = new Web3(web3.currentProvider); } else { web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:7545')); } // stating account web3.eth.defaultAccount = web3.eth.accounts[0]; // Stating Contract Abi var contractAbi = [WHATEVER THE ABI IS ]; // Stating Contract Address var contractAddress = 'WHATEVER THE ADDRESS IS'; // matching abi to contract var contract = web3.eth.contract(contractAbi).at(contractAddress); // action on submit $('form').on('submit', function(sendViaCall) { contract.sendViaCall($('input').val()); }) </script> </body> </html>
I feel the issue is related to the submission, but what do I know. Thank you for any guidance