Here is my onSubmit function:
onSubmitModifyAllocation = async event => {
event.preventDefault();
const accounts = await web3.eth.getAccounts();
await fund.methods.modifyAllocation(this.state.address, this.state.allocation).send({
from: accounts[0],
allocation: web3.utils.toWei(this.state.value, 'ether') // Here is an issue
});
And the form:
<form onSubmit={this.onSubmitModifyAllocation}>
<h4>Modifies the max investment limit allowed for an investor</h4>
<div>
<label>Address </label>
<input
value={this.state.address}
onChange={event => this.setState({ address: event.target.value })}
/>
</div>
<div>
<label>Allocation, denominated in ether </label>
<input
value={this.state.allocation}
onChange={event => this.setState({ allocation: event.target.value })}
/>
</div>
<button>Change allocation</button>
</form>
I've tried to convert the allocation value to BN, but no luck. What's the best approach to managing the error?
web3.utils.toWei
returns astring
or aBN
, see here (I'm assuming that you're using web3.js v1.x). – goodvibration Jan 13 '19 at 11:47BN
to astring
or aBigNumber
. Tell you what - add.toFixed()
at the end of that expression, see if it resolves the problem. – goodvibration Jan 13 '19 at 11:49this.state.value
is a string. (Your code doesn't show this being set anywhere, so it's hard to tell you where the issue is.) – user19510 Jan 13 '19 at 22:01