[英]Openzepplin crowdsale contract got: VM Exception while processing transaction: revert error
我正在开发基于openzeppelin-solidity的智能合约,我想编写一个简单的Crowdsale合约,只有我做的是继承Contract.sol:
// FloatFlowerTokenCrowdsale.sol
pragma solidity 0.4.23;
import "openzeppelin-solidity/contracts/crowdsale/Crowdsale.sol";
contract FloatFlowerTokenCrowdsale is Crowdsale{
constructor(ERC20 _token) public Crowdsale(1000, msg.sender, _token)
{
}
}
这是我的FloatFlowerToken.sol
// FloatFlowerToken.sol
pragma solidity 0.4.23;
import "openzeppelin-solidity/contracts/token/ERC20/StandardToken.sol";
contract FloatFlowerToken is StandardToken {
string public name = "FLOATFLOWER TOKEN";
string public symbol = "FFT";
uint8 public decimals = 18;
constructor() public {
totalSupply_ = 36000000;
balances[msg.sender] = totalSupply_;
}
}
这是我的2_deploy_contract.js
const FloatFlowerToken = artifacts.require('./FloatFlowerToken.sol');
const FloatFlowerTokenCrowdsale =
artifacts.require('./FloatFlowerTokenCrowdsale.sol');
module.exports = function(deployer, network, accounts) {
return deployer
.then(() => {
return deployer.deploy(FloatFlowerToken);
})
.then(() => {
return deployer.deploy(FloatFlowerTokenCrowdsale, FloatFlowerToken.address);
})
};
执行truffle test
并收到Error: VM Exception while processing transaction: revert
出现Error: VM Exception while processing transaction: revert
这是我的测试代码:
it('one ETH should buy 1000 FLOATFLOWER TOKEN in Crowdsale', function(done) {
FloatFlowerTokenCrowdsale.deployed().then(async function(instance) {
const data = await instance.sendTransaction({from: accounts[7], value: web3.toWei(1, "ether")}, function(error, txhash) {
console.log(error);
});
const tokenAddress = await instance.token.call();
const FloatFlowerToken = FloatFlowerToken.at(tokenAddress);
const tokenAmount = await FloatFlowerToken.balanceOf(accounts[7]);
assert.equal(tokenAmount.toNumber(), 1000000000000000000000, 'The sender didn\'t receive the tokens as crowdsale rate.');
})
})
我不知道如何检查错误日志以及不知道哪一行会导致此问题。
您有2个问题:
首先,您正在使用的单位不正确。 您已经初始化了众筹活动,以每发送一次Wei出售1000个代币。 从Zeppelin合同中的文档中:
@param _rate买家每魏获得的令牌单位数
@param _wallet将收集的资金转发到的地址
@param _token所出售代币的地址
您在交易中传递了1个以太币,这意味着您试图购买1000 *(10 ^ 18)令牌单位,但您只分配了总供应量3600万。 您需要增加总供应量和/或降低费率。
其次,除非先完成批准,否则只有令牌所有者才能进行转让。 部署令牌合同时,所有令牌均由msg.sender
拥有。 但是,当某人通过您的众包合同进行购买时,进行转账的请求来自众包合同的地址,而不是部署您的代币合同时的代币所有者。 解决此问题的最简单方法是在部署合同之后,将用于众筹的足够的令牌从您用于创建令牌合同的地址转移到众筹合同的地址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.