The below contract compiles and can be deployed. But when I try to transact using the createProject function, I obtain an error as follows:
transact to Details.createProject errored: VM error: invalid opcode.
invalid opcode
The execution might have thrown.
I am trying to create a smart contract which stores the details (name and description) of a project. My smart contract code is as follows:
pragma solidity ^0.4.17;
contract Details {
// Id number of the project
uint public projcount = 0;
struct Projects {
string projectname;
string description;
}
// A mapping from a student's address to projects he/she is associated with
mapping (address => Projects[]) public Proj;
// Storing the project name and description obtained from input as strings
function createProject (string memory _projectname, string memory _description) public {
Proj[msg.sender][projcount].projectname = _projectname;
Proj[msg.sender][projcount].description = _description;
projcount++;
}
// Retrieving the project details stored using student's address and project id number
function getProject (address _addr, uint _id) public view returns (string, string) {
return (Proj[_addr][_id].projectname, Proj[_addr][_id].description);
}
}
Please let me know what could be possible fix. Many thanks!
Best Answer