0

I´ve spent a couple weeks try to understanding what was heppening. The same solidity code worked great in REMIX but not in Truffle/Ganache. Let´s me explain. I wrote a code bases on Openzeppelin, but it isn´t the same. I changed variables, names, functions. I kept variable as private and I used public functions to access them, I think is a kind of Ethereum propposal. So I had the abstract contract below, just inheritance and constructor is necessary to solve the problem.

contract ERC20 is Context, IERC20, IERC20Metadata, IPTK{ string private name_; string private symbol_; uint8 private decimals_; uint8 private withdrawnDaily_; uint256 private totalSupply_; mapping(address => uint256) private withdraw_; mapping(address => uint256) private balances_; mapping(address => mapping (address => uint256)) private allowed_; constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _totalSupplyMinted, uint8 _withdrawnDaily) { name_ = _name; symbol_ = _symbol; decimals_ = _decimals; totalSupply_ = _totalSupplyMinted; withdrawnDaily_ = _withdrawnDaily; } 

Then I create a contract based on that ERC20.

pragma solidity ^0.8.4; import "./tokens/ERC20.sol"; contract Sample3 is ERC20 { constructor() ERC20("Sample3", "SP3", 18, 58000000000, 1) { } } 

As I told, in Remix it works great. The ERC20 initializes all private variables with right values, but when use truffle/ganache I got the problem. The values are inicializates with wrong numbers as you can see...

truffle-ganache mirate

After many and many tests I found out that the problem happened with all uint´s variables. Example, uint8 (decimals_ variable) works great with numbers until 12, after that then doesn´t matter with number iss passed, it will keep 12 as a maximun value. Something similar occurs with uint256 (totalSupply_ variable) and I guess with all uint types.

Does anyone has faced something like that? What could be happening?

3
  • It's hard to answer this without seeing the code you use to pass those numbers to the creation of the contract, as that's likely where your issue lies Commented Apr 29, 2022 at 15:36
  • But the code is that "ERC20("Sample3", "SP3", 18, 58000000000, 1)" with a pass to " constructor(string memory _name, string memory _symbol, uint8 _decimals, uint256 _totalSupplyMinted, uint8 _withdrawnDaily)". Commented Apr 29, 2022 at 19:48
  • I coded some script to test the values in truffle and it worked great. So, the problem is how ganache pop up the result, I guess. Commented May 3, 2022 at 14:31

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.