使用 OpenZepplin 时我无法转移令牌。我尝试自己运行令牌智能合约,但它完全没问题,没有启动它的实例。下面是我的代码:
import "./tokentrial.sol";
pragma solidity ^0.8.0;
contract solution{
address public solAddress;
uint256 public employerPay;
MyToken public generatedToken;
constructor(address _solAddress){
solAddress = _solAddress;
employerPay = 0;
}
function getAddress()public returns(address){
return solAddress;
}
function getPay(uint256 salary)public{
employerPay = salary;
}
function makeToken() public{
generatedToken = new MyToken(employerPay);
}
function getToken()public returns(MyToken){
return generatedToken;
}
}
contract main{
// employee bank instance
employeeBank public empBank;
// employee instance
employee public emp;
// to generate token
solution public soln;
// solution generated the token
MyToken public createdToken;
uint256 public employerPaid;
address public bossAddress;
constructor(string memory _vaultKey){
security = new vault(_vaultKey);
}
// make instances of all that are involved
function setPartiesAddr(address bossAddr,address empAddr,address bankAddr, address solnAddr)public{
emp = new employee(empAddr);
empBank = new employeeBank(bankAddr);
soln = new solution(solnAddr);
mainManager = new manager();
bossAddress = bossAddr;
}
function payEmployee(uint256 salary)public{
// send token
require(security.getValidity() == true,"vault key must be correct");
employerPaid = salary;
soln.getPay(employerPaid);
soln.makeToken();
createdToken = soln.getToken();
}
function employeeReceiveToken()public{
createdToken.transferFrom(msg.sender,emp.getAddress(),1);
}
function viewSupply()public returns(uint){
return createdToken.totalSupply();
}
}
我不确定我哪里出错了:(因为当我启动“主”智能合约时,一切似乎都很好。我能够毫无问题地创建一个令牌实例。但是,当我想将令牌转移到一个地址时,我提示此错误:
向 main.employeeReceiveToken 交易错误:VM 错误:还原。
revert 事务已恢复到初始状态。合约提供的原因:“ERC20:转账金额超过余额”。调试事务以获取更多信息。
更新:通过使用 OpenZepplin 向导创建合约来解决