I am using ropsten.infura as my provider. It is my very first time to use infura so please bear with me.
This is my code for requesting the transaction.
web3().eth.getTransactionCount(coinbase)
.then(nonce => {
console.log(nonce)
const privateKey = new Buffer(pKey, 'hex')
let data = newContractInstance.methods.redeem('0x91320aBaa4eA71BcDaE54f99eD6a6D36D44539C7', 5).encodeABI()
let rawTx = {
nonce: nonce,
gasPrice: 10000000000,
gasLimit: 3000000,
data: data
}
let Tx = new ETHtx(rawTx)
Tx.sign(privateKey)
let serializedTx = '0x' + Tx.serialize().toString('hex')
web3().eth.sendSignedTransaction(serializedTx)
.then(result => {
console.log(result)
resolve(result)
})
.catch(error => {
console.error(error)
reject(error)
})
I believe that it is successfully contacting the contract but the transaction is being reverted with this error below.
index.js:2178 Error: Transaction has been reverted by the EVM:
{
"blockHash": "0x50af6435e625d8f52043c376ebd7d890651f64fcc847089a781bb700967ea048",
"blockNumber": 4063823,
"contractAddress": "0x253cE628Df83F20AFAD04C86852D154707e1BF62",
"cumulativeGasUsed": 5180761,
"from": "0x91320abaa4ea71bcdae54f99ed6a6d36d44539c7",
"gasUsed": 3000000,
"logs": [],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status": false,
"to": null,
"transactionHash": "0xc52822264a278afdc521b3759d9b4fbb56e4c18d5c52ccb62f90d0741e4dcfc7",
"transactionIndex": 38
}
I am not so sure why the transaction is being reverted. I believe it has nothing to do with the modifiers as I have successfully used the same method using metamask before. One thing I noticed about using the sendSignedTransaction() is the contractAddress property. The given contractAddress is not the contractAddress that I was trying to contact and the value also changes on each transaction. Is it really how it behaves and does it represent the contractAddress that you are going to access? I hope someone can enlighten me with this.
Contract Code
function redeem(address _user, uint256 _amount)
public
hasStarted
onlyOwner
returns (bool)
{
uint256 _balanceOf = balanceOf[_user];
if (totalRemainingToken < _amount) return false;
if (_balanceOf + _amount < _balanceOf) return false;
totalRemainingToken -= _amount;
balanceOf[_user] += _amount;
emit Redeem(msg.sender, _user, _amount);
return true;
}
newContractInstance
in your JS code?I believe it has nothing to do with the modifiers
- why don't you get rid of the modifiers and give it another go, just to verify this assumption of yours?