I'm making a React frontend for an open-source blockchain protocol for tokenized hedge funds. So the question is how to provide the payable function that requires some other value attached (n this case, it's uint _usdEthBasis)?
The case is the user wants to send ether to a contract by this payable function with the uint _usdEthBasis number attached.
// [INVESTOR METHOD] Issue a subscription request by transferring ether
// into the fund
// Delegates logic to the InvestorActions module
// usdEthBasis is expressed in USD cents. For example, for a rate of 300.01,
// _usdEthBasis = 30001
function requestSubscription(uint _usdEthBasis)
whenNotPaused
payable
returns (bool success)
{
var (_ethPendingSubscription, _totalEthPendingSubscription) =
investorActions.requestSubscription(msg.sender, msg.value);
investors[msg.sender].ethPendingSubscription = _ethPendingSubscription;
totalEthPendingSubscription = _totalEthPendingSubscription;
LogSubscriptionRequest(msg.sender, msg.value, _usdEthBasis);
return true;
}
I tried this one, but I got the error:
Unhandled Rejection (Error): Invalid number of parameters for "requestSubscription". Got 0 expected 1!
<form onSubmit={this.onSubmit}>
<h4>Issue a subscription request by transferring ether into the fund</h4>
<div>
<label>Amount of ether to subscribe</label>
<input
value={this.state.value}
onChange={event => this.setState({ value: event.target.value })}
/>
</div>
<div>
<label>usdEthBasis</label>
<input
value={this.state.usdEthBasis}
onChange={event => this.setState({ usdEthBasis: event.target.value })}
/>
</div>
<button>Subscribe</button>
</form>
Here is the onSubmit function:
onSubmit = async event => {
event.preventDefault();
const accounts = await web3.eth.getAccounts();
this.setState({ message: 'Waiting on transaction success...' });
await fund.methods.requestSubscription().send({
from: accounts[0],
usdEthBasis: this.state.value,
value: web3.utils.toWei(this.state.value, 'ether')
});
this.setState({ message: 'You have been entered!' });
};