Hey folks im having trouble funding my contract with web3.
I have a very simple payable function in the contract which is just there to accept money.
function makePayment() public payable returns (bool) {
return true;
}
For my frontend I have a very basic html form just to input some amount and then a button to fund the contract.
Here is my HTML:
<form class="pure-form">
<input id="name" type="text" placeholder="Fund Contract" />
<button type="submit" class="sendMoney"></button>
</form>
<script>
var nameInput = document.getElementById('name');
document.querySelector('form.pure-form').addEventListener('submit', function (e) {
//prevent the normal submission of the form
e.preventDefault();
// console.log(nameInput.value);
});
</script>
Then in my app.js I have a function for sending the money:
sendMoney: function() {
// console.log(nameInput.value);
var practiceInstance;
App.contracts.Practice.deployed().then(function (instance) {
practiceInstance = instance;
return practiceInstance.makePayment().send ({
from: web3.eth.accounts[1],
value: web3.utils.toWei(nameInput.value, 'ether')
});
}).catch(function (err) {
console.log(err.message);
});
},
This^ function is being called when the "sendMoney" button is tapped.
So what's happening is when I write in an amount of ether in the app to send to the contract I get a log message saying "Cannot read property 'toWei' of undefined"
And in my meta mask it shows that 0 ether is being sent to the contract for some reason: