0

I'm currently trying to test run source code from GitHub based on a 2018 tutorial where solidity was using version 0.5.16. I'm currently using truffle v4.1.14. I understand that there was an update from "address" to "address payable", but I'm still not able to get it to work after referencing to similar threads. Appreciate any help. Thanks!

pragma solidity ^0.5.16;

import "./StringUtils.sol";
import "./Accounts.sol";

/** @title Documents. */
contract Documents {
    
  address payable private owner;
  address public accountsAddress;
  Document payable[] private documents;
  mapping (address => Count) private counts;
  enum DocStatus {Pending, Verified, Rejected}
  mapping (address => uint) balances;
 
  struct Document {
    address requester;
    address verifier;
    string name;
    string description;
    string docAddress;
    DocStatus status;
  }
  
  struct Count {
    uint verified;
    uint rejected;
    uint total;
  }

  event DocumentAdded (address user);
  event DocumentVerified (address user);
  event test (uint test);

function verifyDocument(string memory docAddress, DocStatus status) 
  public 
  payable
  {
    for (uint i=0; i<documents.length; i++) {
      if(StringUtils.equal(documents[i].docAddress, docAddress) && documents[i].verifier == msg.sender && documents[i].status == DocStatus.Pending){
        emit DocumentVerified(msg.sender);
        uint price = Accounts(accountsAddress).getPrice(documents[i].verifier);
        balances[documents[i].verifier] -= price;
        if(status == DocStatus.Rejected){
            counts[documents[i].requester].rejected = counts[documents[i].requester].rejected + 1;
            counts[documents[i].verifier].rejected = counts[documents[i].verifier].rejected + 1;
            // return the ether for rejection
            documents[i].requester.transfer(price);
        }
        if(status == DocStatus.Verified){
            counts[documents[i].requester].verified = counts[documents[i].requester].rejected + 1;
            counts[documents[i].verifier].verified = counts[documents[i].verifier].verified + 1;
            // send ether to verified account
            documents[i].verifier.transfer(price);
        }
        documents[i].status = status;
        break;
      }
    }
  }

** Documents.sol:208:13: TypeError: "send" and "transfer" are only available for objects of type "address payable", not "address". documents[i].requester.transfer(price); ^-----------------------------^ **

Full source code: https://github.com/lionel1702/final-project-RumeelHussain/blob/master/contracts/Documents.sol

Error Log: https://github.com/lionel1702/log/blob/master/emailRegexErrorLog4

0

You just need to change a few more of type address to be address payable. Namely here:

struct Document {
    address requester;
    address verifier;
    string name;
    string description;
    string docAddress;
    DocStatus status;
  }

Change into:

struct Document {
    address payable requester;
    address payable verifier;
    string name;
    string description;
    string docAddress;
    DocStatus status;
  }

Possible also changes needed in other parts of the contracts, but this should fix this immediate issue.

| improve this answer | |
  • Another error came through Documents.sol:99:19: TypeError: Invalid type for argument in function call. Invalid implicit conversion from address to address payable requested. verifier: _verifier, ^-------^ – Lionel Lim Sep 2 at 20:18
  • Thank you so much, I did manage to solve this problem too. ethereum.stackexchange.com/questions/71766/… Everything went well. – Lionel Lim Sep 2 at 20:32

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.