我想要完成的是从 ERC721 合约调用 ERC20 合约中定义的函数,如下所示,特别transferFrom
是 ERC20 合约中的函数在 ERC721 中的同一函数内。
这不编译。它最终所做的是,每次发生 erc721 NFT 转移时,版税都会以 erc20 代币的形式转移给创建者。
import "./myToken.sol" as erc20contract //This is my ERC20 contract
contract ERC721 is ERC721Interface, myToken {
function transferFrom(address _from, address _to, uint256 _tokenId) public payable {
address addr_owner = ownerOf(_tokenId);
require(
addr_owner == _from,
"_from is NOT the owner of the token"
);
require(
_to != address(0),
"Transfer _to address 0x0"
);
address addr_allowed = allowance[_tokenId];
bool isOp = operators[addr_owner][msg.sender];
require(
addr_owner == msg.sender || addr_allowed == msg.sender || isOp,
"msg.sender does not have transferable token"
);
//transfer : change the owner of the token
tokenOwners[_tokenId] = _to;
balances[_from] = balances[_from].sub(1);
balances[_to] = balances[_to].add(1);
//reset approved address
if (allowance[_tokenId] != address(0)) {
delete allowance[_tokenId];
}
erc20contract.transferFrom(_to, nftInfo[_from].creator, 10); // This is what I'd like to achieve
{
emit Transfer(_from, _to, _tokenId);
}
}