Contract instantiation

To instantiate an existing contract, we need to know its address. For example, in our contract, we will instantiate the Cplayer contract in the Ctontine constructor as follows:

constructor(address _CplayerAddress) public {    Tplayer = Cplayer(_CplayerAddress);}

The Cplayer(_CplayerAddress); expression will perform an explicit conversion of the Cplayer type, stating that "we know that the contract at the given address of _CplayerAddress is of the Cplayer type." It's worth noting that instantiating a contract using its address doesn’t imply the execution of its constructor.

The interaction with a deployed contract is a very powerful feature as it allows code reusability, since deployed contracts can be used like libraries. ...

Get Blockchain By Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.