![](/img/trans.png)
[英]Call function of smart contract after deploying smart contract in Solidity
[英]Problem with Inheritance in solidity . can not use any function from other smart contract
我有两个智能合约, DEXUserCoin
和DEXTransferCoinUserToUser
。
我想使用 Some Function 从DEXUserCoin
到DEXTransferCoinUserToUser
。
DEX用户币:
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import './DEXCoin.sol';
contract DEXUserCoin {
struct UserCoin {
uint coinId;
uint256 amount;
}
mapping(address => UserCoin) internal userCoins;
constructor() {
}
function ApproveTransferSend(address userAddress , uint coinId , uint256 amount) external view returns(bool) {
if(userCoins[userAddress].amount >= amount && userCoins[userAddress].coinId == coinId) {
return true;
} else {
return false;
}
}
}
需要使用ApproveTransferSend
进入DEXTransferCoinUserToUser
我试试这个:
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
import './DEXUserCoin.sol';
contract DEXTransferCoinUserToUser {
DEXUserCoin private desxUserCoin;
constructor(){}
function TransferUserToUser(address from , address to ,uint coinId , uint256 amount)
public view returns(bool) {
return desxUserCoin.ApproveTransferSend(from,coinId,amount);
}
}
您只是导入但没有继承任何东西:
contract DEXTransferCoinUserToUser is DEXUserCoin {
}
或者您必须在构造函数中设置desxUserCoin
值
constructor (DEXUserCoin _dex){
desxUserCoin=_dex;
}
这个构造函数意味着当你创建合约时,你必须传递一个参数来初始化合约。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.