[英]Openzepplin crowdsale contract got: VM Exception while processing transaction: revert error
I am developing smart contract based on openzeppelin-solidity and I want to write an easy Crowdsale contract, only I did is inherit Contract.sol: 我正在开发基于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)
{
}
}
Here is my FloatFlowerToken.sol 这是我的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_;
}
}
And this is my 2_deploy_contract.js 这是我的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);
})
};
After I execute the truffle test
and I got the error Error: VM Exception while processing transaction: revert
执行
truffle test
并收到Error: VM Exception while processing transaction: revert
出现Error: VM Exception while processing transaction: revert
And here is my test code: 这是我的测试代码:
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.');
})
})
I don't know how to check the error log and to know which line cause this problem. 我不知道如何检查错误日志以及不知道哪一行会导致此问题。
You have 2 issues: 您有2个问题:
First, the units you're working with aren't correct. 首先,您正在使用的单位不正确。 You've initialized your crowdsale to sell 1000 tokens for every Wei sent.
您已经初始化了众筹活动,以每发送一次Wei出售1000个代币。 From the documentation in the Zeppelin contract:
从Zeppelin合同中的文档中:
@param _rate Number of token units a buyer gets per wei
@param _rate买家每魏获得的令牌单位数
@param _wallet Address where collected funds will be forwarded to
@param _wallet将收集的资金转发到的地址
@param _token Address of the token being sold
@param _token所出售代币的地址
You're passing in 1 ether in your transaction, which means you're attempting to buy 1000 * (10^18) token units, but you've only allocated 36000000 total supply. 您在交易中传递了1个以太币,这意味着您试图购买1000 *(10 ^ 18)令牌单位,但您只分配了总供应量3600万。 You need to increase your total supply and/or lower your rate.
您需要增加总供应量和/或降低费率。
Second, only token owners can do a transfer unless an approve has been done first. 其次,除非先完成批准,否则只有令牌所有者才能进行转让。 When you deploy the token contract, all of the tokens are owned by
msg.sender
. 部署令牌合同时,所有令牌均由
msg.sender
拥有。 However, when someone makes a purchase through your crowdsale contract, the request to do the transfer is coming from the address of the crowdsale contract, not the token owner when your token contract was deployed. 但是,当某人通过您的众包合同进行购买时,进行转账的请求来自众包合同的地址,而不是部署您的代币合同时的代币所有者。 The simplest way around this is after deploying your contracts, transfer enough tokens for the crowdsale from the address you used to create the token contract over to the address of the crowdsale contract.
解决此问题的最简单方法是在部署合同之后,将用于众筹的足够的令牌从您用于创建令牌合同的地址转移到众筹合同的地址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.