Reputation: 11991
Using a node.js client, I'm trying to invoke a smart contract function by:
I deployed a simple smart contract:
pragma solidity ^0.4.25;
contract Test {
event MyEvent(address sender, string message, uint sessionId, uint value);
event TestEvent(address sender);
constructor() public {}
function testFunction(string message, uint sessionId)
public payable {
emit MyEvent(msg.sender, message, sessionId, msg.value);
}
function test2()
public {
emit TestEvent(msg.sender);
}
}
I'm having success invoking test2
(when sending an empty parameters array) but failing to invoke testFunction
which takes parameters. I've tried using tronweb triggerSmartContract call:
async function triggerSmartContract() {
try {
const options = {
feeLimit: 1000000000,
callValue: 50
};
const parameters = [{type: 'string', value: 'test-round-id-1'}, {type: 'uint', value: 12345}];
const issuerAddress = tronWeb.defaultAddress.base58;
const functionSelector = 'testFunction(string, uint)';
let transactionObject = await tronWeb.transactionBuilder.triggerSmartContract (
contract_address,
functionSelector,
options,
parameters,
tronWeb.address.toHex(issuerAddress)
);
if (!transactionObject.result || !transactionObject.result.result) {
return console.error('Unknown error: ' + txJson, null, 2);
}
// Signing the transaction
const signedTransaction = await tronWeb.trx.sign(transactionObject.transaction);
if (!signedTransaction.signature) {
return console.error('Transaction was not signed properly');
}
// Broadcasting the transaction
const broadcast = await tronWeb.trx.sendRawTransaction(signedTransaction);
console.log(`broadcast: ${broadcast}`);
} catch (e) {
return console.error(e);
}
}
The code runs and creates a transaction on the blockchain but with result of FAIL-REVERT OPCODE EXECUTED
.
The wallet of the address and key that are defined in tronweb object has enough funds in it (it's not out of gas/not enough funds matter).
Also the function in the smart contract is defined as payable.
Since I can invoke successfully any function with no parameters I tend to think the problem relates to the way I construct the parameters
array. I built the parameters
array this way (pairs of type
and value
) after going over the source code of the transactionBuilder (line 833).
Any suggestions?
Upvotes: 4
Views: 8730
Reputation: 86
Had exactly the same issue. Solution:
const functionSelector = 'testFunction(string,uint)';
as malysh adviseduint
to uint256
Upvotes: 2
Reputation: 60
try writing function parameters without spaces.const functionSelector = 'testFunction(string,uint)';
I read in the documentation that you have to write without spaces, it worked for me on python.
Upvotes: 2