Rate to use for Crowdsale?

I have an ERC20 Mintable+Burnable Token created on solidity 6.11 and a sale contract on solidity 5.0 I am getting error when i send ETH to the sale contract.

Token Contract:

// SPDX-License-Identifier: MIT

pragma solidity 0.6.11;

import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/GSN/Context.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol";

 * @dev {ERC20} token, including:
 *  - ability for holders to burn (destroy) their tokens
 *  - a minter role that allows for token minting (creation)
 *  - a pauser role that allows to stop all token transfers
 * This contract uses {AccessControl} to lock permissioned functions using the
 * different roles - head to its documentation for details.
 * The account that deploys the contract will be granted the minter and pauser
 * roles, as well as the default admin role, which will let it grant both minter
 * and pauser roles to other accounts.
contract BOTToken is Context, AccessControl, ERC20Burnable {
    bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");

     * @dev Grants `DEFAULT_ADMIN_ROLE`, `MINTER_ROLE` and `PAUSER_ROLE` to the
     * account that deploys the contract.
     * See {ERC20-constructor}.
    constructor(string memory name, string memory symbol) public ERC20(name, symbol) {
        _setupRole(DEFAULT_ADMIN_ROLE, _msgSender());

        _setupRole(MINTER_ROLE, _msgSender());

     * @dev Creates `amount` new tokens for `to`.
     * See {ERC20-_mint}.
     * Requirements:
     * - the caller must have the `MINTER_ROLE`.
    function mint(address to, uint256 amount) public virtual {
        require(hasRole(MINTER_ROLE, _msgSender()), "BOTToken: must have minter role to mint");
        _mint(to, amount);

I have given minter role to sale contract. This is the sale contract i am using:

pragma solidity ^0.5.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/tree/v2.5.1/contracts/crowdsale/emission/MintedCrowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/tree/v2.5.1/contracts/crowdsale/validation/CappedCrowdsale.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/tree/v2.5.1/contracts/crowdsale/Crowdsale.sol";

contract BotSale is Crowdsale, MintedCrowdsale, CappedCrowdsale {
constructor (
uint256 rate,
address payable wallet,
IERC20 token,
uint256 cap
Crowdsale(rate, wallet, token)
// solhint-disable-previous-line no-empty-blocks
1 Like

Hi @Farhan_W,

Please see the documentation on calculating rate:

If you want to issue someone “1 TKNfor every 1 ETH”, and your decimals are 18, your rate is 1 .

You can post your contract and token on the forum.

Yes i read the docs prior to making contract. Read it multiple times when testing the contract. i have tried with multiple rates. Tried with 1:1 as a rate. Still transaction won’t go through. Is the code i am using correct? or am i missing something. I have also tried using an AllowanceCrowdsale contract and it worked fine. Though i have to use higher gas when sending eth to sale contract to make it success. I am also planning to add individuallyCapped contract but first i have to make this base contract work.

My main point is to make a contract that works on default gas limit on any wallet. I already have a working contract that uses chainlink pricefeed for ETH/USD price conversion but that contracts needs minimum 150k gas limit when sending ETH to that contract. But i need a contract that works on default gas limit so users don’t have to manually set the higher gas limit.

1 Like

ok I solved it i guess. Used the mintable token on Solidity version 0.5 and it works as expected.

1 Like

Hi @Farhan_W,

I thought the ERC20 from OpenZeppelin Contracts v3.x would have worked too. I didn’t see anything obvious in your code.

A post was split to a new topic: How to write big numbers into a migrations script?

A post was split to a new topic: Check rate for Crowdsale

A post was split to a new topic: Rate to use for Crowdsale for ERC20 token not using 18 decimals