Environment
Tested with truffle version v5.0.11 (pre v5.0.13
) and v5.0.39 (latest version)
OS: Ubuntu 19.04
Zeppelin SDK: “@openzeppelin/cli”: “^2.5.3”,
Ganache CLI v6.7.0 (ganache-core: 2.8.0)
node: v10.16.0
Details
I have a problem executing the mint function on a newly created contract that inherits from the ERC721MetadataMintable
open zeppelin contract.
The code example I have given is just to make it easy to find the issue (and not get distracted). But I have this code in my other project and in the tests it mints tokens without any errors.
Code to reproduce
Run:
git clone git@github.com:JasoonS/broken-openzeppelin-example.git
cd broken-openzeppelin-example && npm i
truffle migrate
This will fail with the following error:
Error: Error: Error: Returned error: VM Exception while processing transaction: revert
And if you run truffle debug <failing transaction hash>
You get the following error (which seems strange, and might be unrelated):
⠋ Stepping...TypeError: Cannot read property 'ref' of undefined
Then to fix this, you can (manually) go into the node_modules folder and comment out lines 27&28 of ./node_modules/@openzeppelin/contracts-ethereum-package/contracts/token/ERC721/ERC721MetadataMintable.sol
so that the mintWithTokenURI
function looks as follows:
function mintWithTokenURI(address to, uint256 tokenId, string memory tokenURI) public onlyMinter returns (bool) {
// _mint(to, tokenId);
// _setTokenURI(tokenId, tokenURI);
return true;
}
Then run rm -rf build && truffle migrate
and now everything will pass (of course it won’t do what it is supposed to).
PS: I know it would be better to stop using truffle for migrations and use openzeppelin, but I have come this far with truffle, and I juts want to get everything to work before I change everything.
2 Likes
Hi @JasoonS,
I suspect the issue is with the syntax of the two mint commands (though I haven’t had any success yet in finding the correct syntax):
console.log(await patronageToken.methods.mintWithTokenURI(accounts[0], 2346, "some message").send(options.txParams))
console.log(await patronageToken.methods.mintWithTokenURI(steward.address, 1, "2").send(options.txParams))
If I comment out the two mint commands above and run migrate, the token is deployed and I can interact with it in truffle console
truffle(development)> token = await ERC721Extended.deployed()
truffle(development)> await token.isMinter("0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1")
true
truffle(development)> await token.mintWithTokenURI("0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1", 2346, "some message")
...
truffle(development)> await token.tokenURI(2346)
'some message'
2 Likes
Hi @abcoathup
Once again, thank you for your help!
I will try run those steps manually until I find a better way.
Please let me know if you find out the solution to this problem.
1 Like
Hi @JasoonS,
You could try doing minting (along with other function calls) in a deploy script.
I don’t know if this suits your needs.
2_deploy_v0.js
// Load zos scripts and truffle wrapper function
const { scripts, ConfigManager } = require('@openzeppelin/cli');
const { add, push, create } = scripts;
async function deploy(options, accounts) {
add({
contractsData: [
{ name: 'ERC721Extended', alias: 'ERC721Patronage' },
]
});
await push(options);
const patronageToken = await create({
...options,
contractAlias: 'ERC721Patronage',
methodName: 'setup',
methodArgs: [
"TestToken", "TT", accounts[0]
]
});
console.log('this should be TRUE:', await patronageToken.methods.isMinter(accounts[0]).call(options.txParams))
//console.log(await patronageToken.methods.mintWithTokenURI(accounts[0], 2346, "some message").send(options.txParams))
//console.log(await patronageToken.methods.mintWithTokenURI(steward.address, 1, "2").send(options.txParams))
}
module.exports = async function (deployer, networkName, accounts) {
// console.log('network', networkName)
const { network, txParams } = await ConfigManager.initNetworkConfiguration({ network: networkName, from: accounts[0] })
await deploy({ network, txParams }, accounts);
}
3_mint.js
const ERC721Extended = artifacts.require("ERC721Extended");
module.exports = async function(deployer, networkName, accounts) {
token = await ERC721Extended.deployed();
await token.mintWithTokenURI(accounts[0], 2346, "some message");
console.log('token URI for token ID 2346: ' + await token.tokenURI(2346))
};