Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TRX Not Forwarding in receive() and fallback() on Tron Despite Successful Transaction #6166

Open
abdullahAttiq opened this issue Feb 12, 2025 · 6 comments

Comments

@abdullahAttiq
Copy link

abdullahAttiq commented Feb 12, 2025

i am trying a thing where recieve funds will instantaniously transfered to a predefined wallet.
after the transfer the transaction passes but the funds get stuck in the contract.
note: this code works alright in EVM chains

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.6;

contract TRXForwarder {
address payable public immutable destination;

event TRXForwarded(uint256 amount);

constructor(address payable _destination) {
   // require(_destination != address(0), "Invalid address");
    destination = _destination;
}

receive() external payable {
    require(msg.value > 0, "No TRX sent");
    payable(destination).call{value: msg.value}("");
}

fallback() external payable {
    require(msg.value > 0, "No TRX sent");
    payable(destination).call{value: msg.value}("");
}

@abn2357
Copy link

abn2357 commented Feb 12, 2025

What does it mean 'the transaction passes but the funds get stuck in the contract'?

@abdullahAttiq
Copy link
Author

What does it mean 'the transaction passes but the funds get stuck in the contract'?

You can see in the code the recieve and fallback functions are sending received funds to destination address. But that doesn't happen and the transaction passes and received funds remain in contract.

@Sunny6889
Copy link

@abdullahAttiq could you show me the Transaction Hash or Transaction Details in TranScan. Example Transaction Details.

@abdullahAttiq
Copy link
Author

Bu

@abdullahAttiq I tried and it is the same result as yours. I figured out the reason. On TRON or even Ethereum, it is not possible to remove native token from someone's wallet on their behalf. You can do something like this with ERC20 tokens, which have an approve functionality, but there is no support for this with native token like TRX. To send TRX out of a wallet, the owner of the wallet must sign a transaction specifying they want to send a certain amount of TRX to a certain address. As smart contract address itself does not have private key, thus there is no signature and the internal transfer TRX will not be success(but the smart contract address still received success).

But this same code worked on eth testnet

@Sunny6889
Copy link

@abdullahAttiq sorry on eth it may allow.

@Sunny6889
Copy link

@abdullahAttiq, I apologize for the previous misleading information. After I created the smart contract, I directly transferred TRX to the contract address using the TranLink Transfer function. However, this does not trigger the smart contract's functions. To successfully transfer TRX to the destination, you need to call triggerSmartContract. You can check my successful test transaction detail here on TranScan.

As I tested, neither TranLink nor TranScan provides an easy way to trigger smart contract functions. I suggest using the wallet CLI instead.

Here’s an example command for the wallet CLI:

triggerContract TLDN155fRL5oXNfAwS8pzwdEeVaSKz2A64 #  # false 100000000 1000000 0 #

For usage reference, visit this link. This command will send 100 TRX and trigger the fallback function of the smart contract at address TLDN155fRL5oXNfAwS8pzwdEeVaSKz2A64.

Additionally, I’ve written a sample Java gRPC method, which you can find here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants