首页 文章

我的智能合约可以使用我的自定义ERC-20吗?

提问于
浏览
0

所以我有一个 Contract ,允许你交换ETH我的自定义ERC20令牌 . 我想与其他智能合约一起使用该自定义ERC20令牌 . 是否有某种方法我必须指定自定义令牌与ETH?

例:

pragma solidity ^ 0.4.24;

/ * * ---如何使用:* 1.将HYPER代币以任意金额发送到智能合约地址 . * 2.通过发送0 HYPER交易(每小时1次)来确认您的利润 3.如果您不退出并且收入超过200%,您只能提取超过200%的 Contract * / Contract HyperLENDtest {

using SafeMath for uint;
mapping(address => uint) public balance;
mapping(address => uint) public time;
mapping(address => uint) public percentWithdraw;
mapping(address => uint) public allPercentWithdraw;

function percentRate()public view returns(uint){uint contractBalance = address(this).balance;

if (contractBalance < 100 ether) {
        return (20);
    }
    if (contractBalance >= 500 ether && contractBalance < 1000 ether) {
        return (40);
    }
    if (contractBalance >= 1000 ether && contractBalance < 2000 ether) {
        return (60);
    }
    if (contractBalance >= 2000 ether) {
        return (80);
    }

我没有返回ETH,而是希望使用我的自定义ERC20令牌发送给 Contract 并返回ERC20令牌的% .

1 回答

  • 0

    您的 Contract 只是另一个地址所以是的,您可以将 Contract 发送给您的 Contract . 但是你不能像发送以太一样发送它们,即使用应付函数 . 您必须将令牌转移到 Contract 's address using the transfer method of you ERC-20 token. And to send tokens from the contract to someone else you have to call transfer from inside your contract unless you do something like provide a lot of allowance for your account, but I wouldn' t建议 . 您可以在this帖子中解释如何从其他 Contract 中调用ERC-20中的方法 .

相关问题