I'm trying to make a frontend of calling a function with an address attached:

function getAvailableAllocation(address _addr)
  returns (uint ethAvailableAllocation)
  return investorActions.getAvailableAllocation(_addr);

Here is onSubmit function:

onSubmit = async event => {

  const accounts = await web3.eth.getAccounts();

  await fund.methods.getAvailableAllocation(this.state.value).call({
    from: accounts[0],
    address: this.state.value

Here is onSubmit form

<form onSubmit={this.onSubmit}>
  <h4>Available allocation</h4>
  <h5>Get the remaining available amount in Ether that an investor can subscribe for</h5>
    <label>Your ethereum address</label>
      onChange={event => this.setState({ address: event.target.value })}
    <button>Get available allocation</button>

When I use an address passed it consolelog the right result. Like so: fund.methods.getAvailableAllocation('0xbe4B62ac6C98bf755dBf217e24FA502A00eC9cf3').call

What I'm doing wrong?

  • what do you mean to say in this sentence: "When I use an address passed it consolelog the right result."
    – Jaime
    Commented Dec 14, 2018 at 17:45
  • 1
    Don't you want this.state.address instead of this.state.value?
    – user19510
    Commented Dec 14, 2018 at 19:00
  • @Jaime I mean the function works and I get the expected result by console.log. Commented Dec 14, 2018 at 20:07
  • 1
    Get rid of address: this.state.value. Commented Dec 15, 2018 at 9:22
  • 1
    And in the then, I suggest that you do something a little more explicit. For example: then(function(result, error) {console.log(JSON.stringify(result));});. Commented Dec 15, 2018 at 9:23

1 Answer 1


If you want to call a solidity function from javascript using web3 v1 you have to do the following

Let's suppose we have this in a contract

event FooTriggered(string message, address who, uint amount);

function foo(address aaa, uint bbb, string sss) public view returns (uint) {
    return 43214321;

To call this function from javascript using web3

const user = '0xabcdefabcdefabcdef...'
const val = 1234
const text = 'Hello'

const res = await myContract.methods.foo(user, val, text).call()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.