Solidity
我在契約中使用已經部署的代幣
我的問題是,如果我沒有在我的契約中實現 ERC-20 方法,但我在我的契約中使用了已經部署的 ERC-20 契約方法,那麼我們可以說這將是符合 ERC-20 的契約嗎?
contract MyContract is Owned { event Created ( uint256 tradeId, uint256 createdAt, uint256 expiredAt, address originatorAddress, address benificiaryAddress, string expectedToken, uint256 receivedQty); event Released(uint256 tradeId); struct Escrow { uint256 tradeId; uint256 createdAt; uint256 expiredAt; address originatorAddress; address benificiaryAddress; string expectedToken; uint256 receivedQty; } mapping (uint256 => Escrow) public escrows; mapping(address => mapping(address => uint256)) public escrowBalance; uint256 feePercent; address feeAddress; // ------------------------------------------------------------------------ // Constructor // ------------------------------------------------------------------------ constructor() public { // escrowBalance[msg.sender][this] = 1000000000; // myToken = ERC20interface(erc20Address) } function createEscrow( uint256 _tradeId, uint256 _expiredAt, address _benificiaryAddress, string _expectedToken, uint256 _receivedQty, address token)payable external { uint256 tokenBalance = ERC20Interface(token).balanceOf(msg.sender); require(tokenBalance >=_receivedQty, "Insufficient balance."); escrows[_tradeId] = Escrow(_tradeId, now, now + _expiredAt, msg.sender, _benificiaryAddress, _expectedToken, _receivedQty); ERC20Interface(token).transferFrom(msg.sender, this, _receivedQty); emit Created (_tradeId, now, now + _expiredAt, msg.sender, _benificiaryAddress, _expectedToken, _receivedQty); } function releaseToken(uint256 _tradeId, address token) external { Escrow storage escrow = escrows[_tradeId]; ERC20Interface(token).transfer(escrow.benificiaryAddress, escrow.receivedQty); emit Released(_tradeId); delete escrows[_tradeId]; } }
ERC-20(又名EIP-20)定義了所有代幣合約都應該實現的標準介面。你的合約沒有實現這個介面,所以你的合約不合規。但是,你的合約不是代幣合約(它不引入自己的代幣,只是使用現有的代幣),所以你的合約不應該實現 ERC-20 介面,因此不應該兼容。
想想所有卡車都必須遵守的一些規定。如果你生產自行車而不是卡車,那麼你的生產很可能不符合這個規定,但這根本不是問題。