How do I create a constructor in solidity?
My goal is to have values initialized when the smart contract is deployed. As a java programmer, I default to a constructor to handle this.
contract NimGamev3 {
...
constructor(NimGamev3) internal {
...
}
...
}
I've read that you should use the constructor keyword to create a constructor to initialize values. This doesn't raise any errors when using remix. When I copy the code to Ethereum Wallet I get an error, "Could not compile source code. Expected identifier, got 'eth_compileSolidty' constructor(NimGamev3) internal {"
When I use a function to initialize variables, it is not called on when the contract is deployed, and if I make it public, it can be initialized multiple times which is not the intended function of the constructor.
Note: I am currently using 0.4.21
Best Answer
The use of the name
constructor
for the constructor is in the version0.4.22
of Solidity. You are using0.4.21
, which doesn't implement it.