I'm trying to use javascript to access the token variables and functions provided in the MintToken.sol file in openzeppelin.
I used "truffle init webpack" to create the metacoin example provided by truffle. I use "truffle compile", "truffle migrate" and "npm run dev" to have an application running in javascript that, using web3, let me interact with the smart contract.
I would like to do the same with zeppelin-solidity. So I created my crowdsale smart contract :
pragma solidity ^0.4.11;
import '../node_modules/zeppelin-solidity/contracts/crowdsale/Crowdsale.sol';
contract MyCrowdsale is Crowdsale {
function MyCrowdsale(uint256 _startTime, uint256 _endTime, uint256 _rate, address _wallet)
Crowdsale(_startTime, _endTime, _rate, _wallet)
{
}
}
Crowdsale.sol has some fields and a mintable token:
contract Crowdsale {
using SafeMath for uint256;
MintableToken public token;
// start and end timestamps where investments are allowed (both inclusive)
uint256 public startTime;
uint256 public endTime;
....
MintableToken.sol inherits from StandardToken (that has balanceOf method) and has some variables:
contract MintableToken is StandardToken, Ownable {
event Mint(address indexed to, uint256 amount);
event MintFinished();
bool public mintingFinished = false;
....
The problem I have is that I'm able to access to the crowdsale variables like startTime and endTime, but I'm not able to access to token variables/methods like balanceOf, mintingFinished, etc.
In my app.js I tried to copy the code used to access the metacoin contract so I'm able to get the startDate, for example:
MyCrowdsale.deployed().then(function(instance) {
return instance.startTime.call();
}).then(function(value) {
var startDate = value.valueOf();
console.log("The startDate is " + startDate);
}).catch(function(e) {
console.log(e);
self.setStatus("Error getting startDate; see log.");
});
I can get the token address using this call:
MyCrowdsale.deployed().then(function(instance) {
return instance.token.call();
}).then(function(mintedToken) {
console.log("The mintedToken is " + mintedToken.valueOf());
}).catch(function(e) {
console.log(e);
});
But I'm stuck here. I would like to access to token.balanceOf() or token.mintingFinished but I don't know how to do it.
I tried (after getting the token address like I wrote before):
console.log("mintingFinished = " + mintedToken.mintingFinished);
and also:
mintedToken.mintingFinished.call().then(function(x) {
console.log("mintingFinished = " + x);
})
But none of these approaches worked.
Any help would be appreciated.