简体   繁体   English

Openzepplin众包合同获得:处理事务时VM异常:恢复错误

[英]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.

相关问题 松露错误:错误:处理事务时VM异常:恢复 - Truffle error: Error: VM Exception while processing transaction: revert “VM Exception while processing transaction: revert”,当运行chainlink节点并尝试部署TestnetConsumer合约时? - "VM Exception while processing transaction: revert", when running a chainlink node and try to deploy TestnetConsumer contract? 无法弄清楚为什么在处理事务时出现 VM 异常:恢复错误 - Cannot figure out why I am getting VM Exception while processing transaction: revert error 错误:返回错误:处理事务时出现 VM 异常:恢复余额不足 — 给出的原因:余额不足 - Error: Returned error: VM Exception while processing transaction: revert Not Enough Balance — Reason given: Not Enough Balance 错误 Truffle Migrate “处理事务时出现 VM 异常:操作码无效” - Error Truffle Migrate "VM Exception while processing transaction: invalid opcode" 处理事务时出现 VM 异常:恢复 TransferHelper: TRANSFER_FROM_FAILED 运行 bot.js 的 manipulatePrice.js 测试时 - VM Exception while processing transaction: revert TransferHelper: TRANSFER_FROM_FAILED when running manipulatePrice.js test for bot.js 我正在为合同添加价值,但我收到此错误“VM 错误恢复” - i'm addming a value to the contract but i recevie this error "VM error revert" 在 Hedera 区块链中创建智能合约时出现错误“交易过大” - Getting error "Transaction Oversize" while creating a smart contract in Hedera blockchain 尝试签署交易时出现 Assertion.failed 错误 - Got Assertion.failed error while trying to sign a transaction ETH ICO众筹合同延期奖励KYC - ETH ICO Crowdsale contract hold back reward for KYC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM