I've been developing a dApp that needs ERC721 tokens. I have three contracts, a base contract, the one to mint tokens and another one for auctions. The inheritance looks like Base > Token > Auctions. In this scenario AFAIK I should be able to access the functions from the Token contract from the Auctions one. When minting new tokens I call a function of Base from Token and the token is minted successfully, I can check the information of the token if I call the contract directly, i.e. from Truffle console
CToken.deployed().then(i => { return.i.ownerOf(0) })
This works after minting obviously but when I try to call that function from the Auctions contract the operation reverts.
truffle(development)> Auctions.deployed().then(i => { return i.__ownerOf.call(0) })
Error: VM Exception while processing transaction: revert
... Whole stacktrace...
Why can't I get this information? It should be noted that if I call the mint
function from another contract (Auctions or Base) I can get this information from those contracts but not from the Token one like if the storage is only for the contracts that called those functions initially. What I'm missing here?
Here are the relevant functions:
Token:
function createStallion(address _sender, string _hash) public payable {
require(stallionsAvailable > 0);
uint256 tokenId = addresses.push(_sender) - 1;
super._mint(_sender, tokenId); // This comes from OpenZeppelin.
super.buyStallion(_hash);
stallionsAvailable -= 1;
}
function ownerOf(uint256 _tokenId) public view returns(address) {
return super.ownerOf(_tokenId);
}
Base
function buyStallion(string _horseHash) internal returns(bool) {
counter += 1;
Horse memory horse;
// ... bunch of horse information
horses.push(horse);
return true;
}
Auctions:
// This function is only for testing since I'm not calling it anywhere yet but it had the same behaviour when I wanted to use it in a `require`
function __ownerOf(uint256 _horseId) public view returns(address) {
return super.ownerOf(_horseId);
}
super
contract?return super.ownerOf(_tokenId)
?contract Base {}
,contract Token is Base, ERC721Token {}
andcontract Auctions is Token {}
so it should inherit that function and be accessible with thesuper
keyword, right?ownerOf
is somewhere higher up in the chain of contracts. (In ERC721BasicToken it seems, if you're using OpenZeppelin).return super.ownerOf(_tokenId);
in your token contract? Your callingsuper
but from my brief understanding, it seems liketoken
is the highest contract, so it shouldn't besuper
but justownerOf
?