我需要使用 Truffle 调用另一个合约中的函数。这是我的合同样本:
类别.sol:
contract Category {
/// ...
/// @notice Check if category exists
function isCategoryExists(uint256 index) external view returns (bool) {
if (categories[index].isExist) {
return true;
}
return false;
}
}
帖子.sol:
contract Post {
/// ...
/// @notice Create a post
function createPost(PostInputStruct memory _input)
external
onlyValidInput(_input)
returns (bool)
{
/// NEED TO CHECK IF CATEGORY EXISTS
/// isCategoryExists() <<<from Category.sol>>>
}
}
部署.js
const Category = artifacts.require("Category");
const Post = artifacts.require("Post");
module.exports = function (deployer) {
deployer.deploy(Category);
deployer.deploy(Post);
};
我能做些什么?
您可以从其他合同继承。假设您想从邮政合同导入。
contract Category is Post {
/// ...
/// @notice Check if category exists
function isCategoryExists(uint256 index) external view returns (bool) {
if (categories[index].isExist) {
return true;
}
return false;
}
// you can call createPost
createPost(){}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)