2

Somebody please help me find the correct pattern to make this solidity error disappear, I'm using specifically solc^0.8.0, here is my code snippet :

function fundAirline() 
    isAirlineRegistered(msg.sender) 
    requireIsOperational
    paidEnough(FUNDING_REQUIRED) 
    checkValue(FUNDING_REQUIRED) external payable {
    
    flightSurety.fundAirline.value(msg.value)(msg.sender); // the problem is in this line
    emit AirlineFunded(flightSurety.getAirlineName(msg.sender), msg.sender); 
}

The problem is in the line : flightSurety.fundAirline.value(msg.value)(msg.sender); it raise the following complaining :

Using ".value(...)" is deprecated. Use "{value: ...}" instead.

Thank you.

2
  • instead of .value(msg.value), use {value: msg.value} The line becomes flightSurety.fundAirline{value: msg.value}(msg.sender);
    – phaze
    Dec 26, 2021 at 12:09
  • Yes, I use it, and it fixed my code, thank you.
    – Yaa_seen
    Dec 27, 2021 at 11:47

1 Answer 1

3

I had faced this on invoking call and had found from Solidity docs that gas and value parameters need to be passed in curly brackets now:

address(nameReg).call{gas: 1000000, value: 1 ether}(abi.encodeWithSignature("register(string)", "MyName"));

Here's the code snippet reflecting the issue I faced with the fix.

CODE WITH SIMILAR PROBLEM:

(bool success, ) = payable(msg.sender).call.value(withdrawalAmt)('');

FIX:

(bool success, ) = payable(msg.sender).call{ value: withdrawalAmt }('');

Though you are NOT using call, the base principle remains the same as you are invoking a contract function and so, applying above fix to your issue:

CODE WITH PROBLEM:

flightSurety.fundAirline.value(msg.value)(msg.sender);

PROPOSED FIX*****

flightSurety.fundAirline{ value: msg.value }(msg.sender);

Also came across this on ESE, it provides relevant clarity: Ethereum.StackExchange - Calling a payable function in another contract with value and arguments

Hope this helps.

2
  • The error vanished after using the proposed code, thank you so much :)
    – Yaa_seen
    Dec 27, 2021 at 11:45
  • @Yaseenix: Thanks for confirming - glad that I could be of help. Dec 27, 2021 at 12:31

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.