1

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!' });
    };
  • @MaheshRajput Please add your reply as an answer. – Ismael Dec 15 '18 at 20:18
  • Done @Ismael, my comment posted as an answer. – Mahesh Rajput Dec 17 '18 at 4:32
2

You forget to pass parameter as this.state.value inawait fund.methods.requestSubscription(<here you forgot to pass>).

0

await fund.methods.requestSubscription() -- here you need to specify the unit argument you need to pass, it's just like a method call, pass the arg in requestSubscription(< args>)

Moreover, if you want to pass the sender, {from: sender_addr}in the args space, separated by a comma.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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