1

I'm trying to get myself familiarized with ethereum. So I was going through a repo, and tried to rum the code :

function transferFundOnResolve(uint cid) private {
        // Could also be used: complainMap[cid]._status == Status.Resolved && 
        if(complainMap[cid]._reward > 0) {
            if(policeAccounts[complainSolver[cid]] != true) {
                complainSolver[cid].transfer( complainMap[cid]._reward );
                complainMap[cid]._reward = 0;
            }
            else {
                for(uint i=0; i<complainMap[cid]._contributors.length; i++) {
                    complainMap[cid]._contributors[i].transfer( complainMap[cid]._contAmount[i] );
                }
                complainMap[cid]._reward = 0;

            }
        }
    }

As it says TypeError: "send" and "transfer" are only available for objects of type "address payable", not "address".

So I modified and added payable() like :

function transferFundOnResolve(uint cid) private {
        // Could also be used: complainMap[cid]._status == Status.Resolved && 
        if(complainMap[cid]._reward > 0) {
            if(policeAccounts[complainSolver[cid]] != true) {
                complainSolver[cid].transfer( payable(complainMap[cid]._reward) );
                complainMap[cid]._reward = 0;
            }
            else {
                for(uint i=0; i<complainMap[cid]._contributors.length; i++) {
                    complainMap[cid]._contributors[i].transfer( payable(complainMap[cid]._contAmount[i]) );
                }
                complainMap[cid]._reward = 0;

            }
        }
    }

Now it says : ParserError: Expected primary expression.

How should I resolve this ?

I have pragma solidity ^0.5.16;

1
  • Please add the code where you declared variables. (Like complainMap and contributors)
    – Masoud jt
    Jun 11 '20 at 2:53
1

The reason you got that error because there is no function name payable that take an integer value and return payable address. The parser doesn't recognise it and give you an error like that.

I don't know your complainMap struct but i can guess that in it contain contrivutor variable and it's type is address. In solidity version greater than 0.5.0 they add payable address (you can see more at here: What's the difference between 'address' and 'address payable'?). The transfer function can only be use on address payable not address so the solution is to change the variable type of contributor from address to address payable or cast it to address payable.

4
  • Can you please tell me, how to cast from address to address payable ?? And updating the question with my structure soon Jun 11 '20 at 4:59
  • I found here : ethereum.stackexchange.com/a/64109/61100, that I can use payable like this Jun 11 '20 at 5:17
  • 1
    @Maifee UI Asad To convert from address to address payable you need payable function which can only be use in solidity 0.6.0 and up. But you are using solidity 0.5.18, that mean it is impossible to convert from address to address payable. So the only way is to change variable address to address payable
    – haxerl
    Jun 11 '20 at 6:02
  • hey @haxerl can you show some example code on how casting to address payable worked for you. Ive tried casting to address payable and still getting the same error. To reproduce error: do truffle test on github.com/iansamz/Simple-Bank-Solidity.git
    – Ian Samz
    Apr 21 at 23:01

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.