While trying to compile this contract I'm getting a syntax error complaining about the "var" keyword being disallowed. How do I fix this?

pragma solidity ^0.5.0;

contract Courses {

    struct Instructor {
        uint age;
        string fName;
        string lName;

    mapping (address => Instructor) instructors;
    address[] public instructorAccts;

    function setInstructor(address _address, uint _age, string memory _fName, string memory _lName) public {
        var instructor = instructors[_address];

        instructor.age = _age;
        instructor.fName = _fName;
        instructor.lName = _lName;

        instructorAccts.push(_address) -1;

    function getInstructors() view public returns (address[]) {
        return instructorAccts;

    function getInstructor(address _address) view public returns (uint, string memory, string memory) {
        return (instructors[_address].age, instructors[_address].fName, instructors[_address].lName);

    function countInstructors() view public returns (uint) {
        return instructorAccts.length;

  • Do you know what the type of instructors[_address] is? – goodvibration Apr 12 '20 at 19:06
  • No, is there a way to check typing? – Levia Apr 13 '20 at 0:36
  • Then you should learn the basics of the language before you start coding. This definitely doesn't look like your work, since there is an obvious use of types here, and the compiler is 0.5.x, which means that the var keyword is long gone. How could someone write all this, and just randomly choose to use var in a single specific place? I'm guessing you've merged two different pieces of code that you've found somewhere? Nothing wrong with that of course, but you gotta know what you're doing, otherwise our help is not gonna get you much further passed this specific problem. – goodvibration Apr 13 '20 at 5:42
  • Change var to Instructor storage, and good luck solving the next problem. – goodvibration Apr 13 '20 at 5:45

I see you're using solidity 0.5.0 and up. As you can see here, var was deprecated in version 0.4.20. Therefore, since your mapping is pointing to an Instructor struct, simply replace

var instructor = instructors[_address];


Instructor storage instructor = instructors[_address];
  • @Levia If this answered your question please accept it so others can see – Elliot Solskjaer Apr 13 '20 at 20:34

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.