I'm doing the CryptoZombies tutorial to get a better handle on solidity and in one of the chapters it contains the following code
pragma solidity ^0.4.19;
import "./zombiefactory.sol";
contract KittyInterface {
function getKitty(uint256 _id) external view returns (
bool isGestating,
bool isReady,
uint256 cooldownIndex,
uint256 nextActionAt,
uint256 siringWithId,
uint256 birthTime,
uint256 matronId,
uint256 sireId,
uint256 generation,
uint256 genes
);
}
contract ZombieFeeding is ZombieFactory {
address ckAddress = 0x06012c8cf97BEaD5deAe237070F9587f8E7A266d;
KittyInterface kittyContract = KittyInterface(ckAddress);
function feedAndMultiply(uint _zombieId, uint _targetDna) public {
require(msg.sender == zombieToOwner[_zombieId]);
Zombie storage myZombie = zombies[_zombieId];
_targetDna = _targetDna % dnaModulus;
uint newDna = (myZombie.dna + _targetDna) / 2;
_createZombie("NoName", newDna);
}
function feedOnKitty(uint _zombieId, uint _kittyId) public {
uint kittyDna;
(,,,,,,,,,kittyDna) = kittyContract.getKitty(_kittyId);
feedAndMultiply(_zombieId, kittyDna);
}
}
My question is in the KittyInterface kittyContract = KittyInterface(ckAddress)
line.
In the local contract ZombieFeeding
, there is no reference to KittyInterface
, nor is there any context given on why the contract address is passed as a parameter to the contract.
I'm assuming that the address being passing into the contract is allowed because solidity uses this interface to point to some external contract, but it gives no explicit reason why I can reference KittyInterface in my ZombieFeeding contract.
My guess here is that KittyInterface is treated as a global variable, but again, I'm not sure.