Hello,
I’m trying to build a Token and first things first I’m following some tutorials and examples.
But I’m encountering an issue with the SimpleToken example:
using "@openzeppelin/contracts": "^2.4.0",
pragma solidity ^0.5.0;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";
contract SimpleToken is ERC20, ERC20Detailed {
/**
* @dev Constructor that gives _msgSender() all of existing tokens.
*/
constructor () public ERC20Detailed("SimpleToken", "SIM", 18) {
_mint(_msgSender(), 10000 * (10 ** uint256(decimals())));
}
}
I run a local blockchain with ganache-cli --deterministic
Then I deploy the contract using openzeppelin create SimpleToken
which gives me back an address that I put in this simple nodejs code:
const Web3 = require('web3');
async function main() {
// Set up web3 object, connected to the local development network
const web3 = new Web3('http://localhost:8545');
const address = '0xC89Ce4735882C9F0f0FE26686c53074E09B0D550';
const abi = require('./build/contracts/SimpleToken.json').abi;
const token = new web3.eth.Contract(abi, address);
const name = await token.methods.name().call();
console.log(name);
}
main();
But no data is displayed, it’s empty. If I try to use the ganache app to get a GUI, I can’t explore the contract it fails with a JS error. Something about address undefined, I’m not sure the problem is related though.
I’m stuck now.
FYI, the Counter smartcontract worked, I could increase the counter, etc…
I’ll try to add parts of the code little by little to see what’s wrong but it’s a bit tedious and I would like to use this library.
Thank you in advance for your help.
Best regards
Gregory