While I use MintableToken and call the mint function from user that not owner of the contract, it always throw this error: VM Exception while processing transaction: revert.
I think is the modifier using require instead revert.
Maybe is like this issue? https://github.com/trufflesuite/ganache-cli/issues/397
os: win10
ethereumjs-testrpc: ^6.0.3
Truffle: 4.0.0 (core: 4.0.0)
Solidity: 0.4.18 (solc-js)
The mint function has the modifier onlyOwner on it so that only the owner can call it. If you look at Ownable.sol where the modifier comes from, it consists of a require(msg.sender == owner) statement. If this statement is false, such as calling the mint function from a user that is not the owner, the require statement compiles to 0xfd which is the opcode for revert. That's why you get the revert exception.
Thanks for explaning @nedodn.
Hi, so far as I know, owner is the one who deploys the contract first & if this is correct, I have checked contract after deploying using this command ContractName.deployed() on truffle console. It shows me from address using which only I'm calling following function:
function changeMyString(string _newString) onlyOwner {
myString = _newString;
}
& a modifier written for that:
modifier onlyOwner {
require (msg.sender == owner);
_;
}
My question is how do I communicate with this function using truffle console? I’m trying something like this:
ProofOfExistence.at(ProofOfExistence.address).changeMyString(“abcdef”)
but it throws me an error stating “VM Exception while processing transaction: revert”
Please help.
The best place for debugging things like this would be the #beginners channel in the open zeppelin slack.
Are you including Ownable in your contract that you've written? I can't see the rest of the code, but you may not have set owner to anything. Likewise, if you are including Ownable, it already provides onlyOwner for you, so there's no need to overwrite it.
That said, there's not much way to debug this without the full contract.
Instead of replying here, please follow up in the OpenZeppelin slack #beginners channel for assistance
I was running into this because I didn't set a from address when testing a MintableToken (which is Ownable). Solved it by doing something like:
const MyMintableToken = artifacts.require('./MyMintableToken.sol')
contract('MyMintableToken', ([owner, ...accounts]) => {
var instance
beforeEach('setup contract for each test', async () => {
instance = await MyMintableToken.new({from: owner})
})
it('should start with no tokens', async () => {
assert.equal(
(await instance.totalSupply()).toNumber(),
0,
)
})
})
That's odd. When you deploy a contract, the web3.eth.defaultAccount is used by default, and truffle automatically sets that in your testing environment. And because Ownable uses msg.sender to register the first owner, it shouldn't be necessary to specify owner as long as it's the first account in the list (the one that will deploy the contract).
Does the deploy itself succeed if you remove the { from: owner } argument?
D'oh! You're absolutely right. Just tried with await AChips.new() instead, and it worked just fine! I must have had something else littering my setup.
Thanks for clarifying!
I 'm getting this error when trying a StandardToken.transferFrom. To set some context I have this OZ based CrowdSale example and unit tests all running on my laptop. I 'm trying to add a new test for transferring tokens like this.
let contractInstance
let tokenInstance
beforeEach('Setup', async () => {
contractInstance = await HashnodeCrowdsale.deployed()
const tokenAddress = await contractInstance.token.call()
tokenInstance = HashnodeToken.at(tokenAddress)
})
it('Token transfer', async () => {
const contractInstance = await HashnodeCrowdsale.deployed()
let ecoSystemBalance = await web3.eth.getBalance(accounts[9])
const owner = await hashToken.owner.call()
console.log(owner)
await tokenInstance.approve(accounts[4], 4)
console.log(await tokenInstance.allowance(owner, accounts[4]))
await tokenInstance.transferFrom(owner, accounts[4], 3)
let receiverBalance = await web3.eth.getBalance(accounts[4])
receiverBalance = receiverBalance.toNumber()
assert.equal(receiverBalance, 3, 'Transfer failed')
})
But it fails like this:
0x2365bb623ec45da3c78578b6c4ecb645816d5a57
BigNumber { s: 1, e: 0, c: [ 0 ] }
Events emitted during test:
---------------------------
Approval(owner: <indexed>, spender: <indexed>, value: 4)
---------------------------
Error: VM Exception while processing transaction: revert
at Object.InvalidResponse (node_modules/truffle-contract/node_modules/web3/lib/web3/errors.js:38:16)
at node_modules/truffle-contract/node_modules/web3/lib/web3/requestmanager.js:86:36
at node_modules/truffle-provider/wrapper.js:134:9
at XMLHttpRequest.request.onreadystatechange (node_modules/truffle-provider/node_modules/web3/lib/web3/httpprovider.js:128:7)
at XMLHttpRequestEventTarget.dispatchEvent (node_modules/xhr2/lib/xhr2.js:64:18)
at XMLHttpRequest._setReadyState (node_modules/xhr2/lib/xhr2.js:354:12)
at XMLHttpRequest._onHttpResponseEnd (node_modules/xhr2/lib/xhr2.js:509:12)
at IncomingMessage.<anonymous> (node_modules/xhr2/lib/xhr2.js:469:24)
at endReadableNT (_stream_readable.js:1055:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
Tried from Truffle console like this and it also fails:
tokenInstance.transferFrom(sourceAddr,destAddr,1)
Once this works I 'm hoping to try this outside Truffle in a node.js/express server and better understand who owns the token contract and how to effect transfers.
By default all transactions are signed with with first account in your accounts list. As such, your await tokenInstance.transferFrom(owner, accounts[4], 3) transaction is signed by accounts[0] not the account that was approved by await tokenInstance.approve(accounts[4], 4) (that line says that accounts[4] is allowed to move 4 tokens from msg.sender's token balance.
Anyway, your solution is probably to change the line to something like token.transferFrom(owner, accounts[4], 4, { from: accounts[4] })
I'm locking this issue
It has very high SEO visibility for a very generic error message. This issue will never be the correct place to raise questions like this, as they will always need to be handled on a case-by-case basis. The correct forum for this error is probably stack overflow #ethereum or the OpenZeppelin slack (slack.openzeppelin.org) if using OpenZeppelin.
If you've found this page, here are some tips for debugging this error:
truffle/web3<1.0.0 is also Bad Software are doesn't tell you _which_ transaction caused the error
Most helpful comment
The mint function has the modifier onlyOwner on it so that only the owner can call it. If you look at Ownable.sol where the modifier comes from, it consists of a require(msg.sender == owner) statement. If this statement is false, such as calling the mint function from a user that is not the owner, the require statement compiles to 0xfd which is the opcode for revert. That's why you get the revert exception.
See: https://ethereum.stackexchange.com/questions/15166/difference-between-require-and-assert-and-the-difference-between-revert-and-thro