I am getting address value with html input as string value how do we convert the string to address for parsing with truffle-contract.

Here's the method I am using:

registerAirline : async() => {
        const airline = document.getElementById('airlineAddress').value;
        const flightApp = await flightSuretyApp.deployed();
        await flightApp.registerAirline(web3.utils.toChecksumAddress(airline), {from: account});

I am getting this error as it's not able to parse string address as address format.

Error: Invalid number of parameters for "registerAirline". Got 2 expected 4!

Well the parameters are correct in case I will paste them down here too.

Here's the function for flightSuretyApp

function registerAirline(address airline) external requireIsOperational() airlineIsFunded(msg.sender) airlineIsNotRegistered(airline) returns (bool success, uint256 votes) {
        if (getRegisteredAirlines() < MULTIPARTY_MINMUM_AIRLINES) {
            flightSuretyData.registerAirline(airline, msg.sender);
            airlineMultiCallers[airline] = [msg.sender];
            return (success, airlineMultiCallers[airline].length);
        } else {
            bool isDuplicate = false;
            for (uint c = 0; c < airlineMultiCallers[airline].length; c ++) {
                if (airlineMultiCallers[airline][c] == msg.sender) {
                    isDuplicate = true;
            require(!isDuplicate, "Voting airline has already submitted vote for this new airline");

            if (airlineMultiCallers[airline].length >= getRegisteredAirlines().div(MULTIPARTY_CONSENSUS_DIVIDER)) {
                flightSuretyData.registerAirline(airline, msg.sender);
                return (success, airlineMultiCallers[airline].length);

            return (false, airlineMultiCallers[airline].length);

Here's the code for flightSuretyData:

function registerAirline(address airline, address caller) external requireIsOperational isAuthorizedCaller isAirlineFunded(caller) {
            airlines[airline] = Airline(true, false);
            registeredAirlines = registeredAirlines + 1;
            emit AirlineRegistered(airline);
  • There's no function here which takes 4 parameters, meaning - the code that you've posted and the error that you've posted are not related. – goodvibration May 23 at 18:11
  • Also, any reason for that last piece of code in your question? Is it there in order to add some confusion to the reader? – goodvibration May 23 at 18:13
  • @goodvibration that's why the problem seems with the string address from the html. Well they are the functions for registerAirline() – Sagar Atalatti May 23 at 18:14
  • expected 4 implies that the solidity function takes 4 parameters. No such function in your code. – goodvibration May 23 at 18:15
  • @goodvibration buts that function I am calling in my index.js I did re-checked with the typos incase but those are the functions from two contracts. The required parameter is 1 for the 1st contract which inherits the function from another contract with 2 parameters. – Sagar Atalatti May 23 at 18:17

Your Answer

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

Browse other questions tagged or ask your own question.