When calling sendSignedTransaction I got:
VM Exception while processing transaction: stack underflow
Used code is below, using TESTRPC:
const serializeTx = async (contractInstance, publicKey, privateKey, funcData) => {
let privateKeyBuff = new Buffer(privateKey, 'hex');
const gasLimit = 500000;
const nonceNumber = await web3.eth.getTransactionCount(publicKey);
const nonce = web3.utils.toHex(nonceNumber);
const gasPrice = web3.utils.toHex(web3.eth.gasPrice);
const gasLimitHex = web3.utils.toHex(gasLimit);
const rawTx = {
'nonce': nonce,
'gasPrice': gasPrice,
'gasLimit': gasLimitHex,
'from': publicKey,
'to': contractInstance.address,
'data': funcData
};
let tx = new EthereumTx(rawTx);
tx.sign(privateKeyBuff);
return '0x' + tx.serialize().toString('hex');
};
let funcData = MyContract.methods.reserve(param).encodeABI();
const serializedTx = await serializeTx(
MyContract,
body.callerPublicKey,
body.callerPrivateKey,
funcData,
);
let result = await web3.eth.sendSignedTransaction(serializedTx);
Same contract function is working nice in Remix, also working nice when called using truffle-contract. Now when I try to sign the transaction data it throws
Error: Returned error: VM Exception while processing transaction: stack underflow
EDIT:
The problem was using contractInstance.address
it should be contractInstance._address