I'm currently at the end of the Ethereum Blockchain Developer Bootcamp With Solidity (2021) course on Udemy and the final project is to change a fixed supply Token to a Mintable token. We're using Solidity 0.6.1 here. I'm having some issues adding the MinterRole of the token during deployment. I'm also lousy at Javascript (working on improving that. Just need to get through this final project first). Here's how I'm attempting to do it in 2_deploy_contracts.js
let token = await MyToken.deployed();
await token.methods.addMinter(deployer.address).call({from: deployer.address});
When I attempt to migrate I'm getting the following error.
TypeError: token.methods.addMinter is not a function
However if I console.log(token.methods), there it is right there:
{
'addMinter(address)': [Function] {
call: [Function],
sendTransaction: [Function],
estimateGas: [Function],
request: [Function]
},
So any idea what I might be doing wrong?
Edit: As requested here is my entire 2_deploy_contracts.js
var MyToken = artifacts.require("MyToken.sol");
var MyTokenSale = artifacts.require("MyTokenSale");
var MyKycContract = artifacts.require("KycContract");
require("dotenv").config({path: "../.env"});
module.exports = async function(deployer) {
let addr = await web3.eth.getAccounts();
await deployer.deploy(MyToken);
await deployer.deploy(MyKycContract);
await deployer.deploy(MyTokenSale, 1, addr[0], MyToken.address, MyKycContract.address);
let token = await MyToken.deployed();
console.log(token.methods);
await token.methods.addMinter(deployer.address).call({from: deployer.address});
}
Edit2:
Ok I seem to have solved it. I was trying to add the deployer address when I should have been passing in the Crowdsale (myTokenSale) address. My experimenting with .call was out of desperation. This seems to have worked.
let token = await MyToken.deployed();
let tokenSale = await MyTokenSale.deployed();
await token.addMinter(tokenSale.address);