1
let contract = await window.tronWeb.contract().at(config.contract);
let result = await contract.methods.depositTron()
 .send({callValue:amount*1000000})
 .then(output=>transaction = output);
console.log("result", result);

I tried to get the result of depositTron method, but returned hash value. how should I do? please help me.

Alexsander
  • 11
  • 2

1 Answers1

0

Functions invoked by transactions only return value within the EVM (usually when called from another contract).

The hash returned from the send() JS function, is the transaction hash.

You can workaround this by emitting an event log within the contract. Then you can get the value or read emitted logs from the transaction receipt (emitted in JS after the transaction is mined).

Solidity:

contract MyContract {
    event Deposit(uint256 indexed amount);

    function depositTron() external payable {
        emit Deposit(msg.value);
    }
}

JS:

contract.methods.depositTron().send({callValue:amount*1000000})
.on('receipt', (receipt) => {
    console.log(receipt.logs);
})
Petr Hejda
  • 40,554
  • 8
  • 72
  • 100