
Tron - How to talk to a smart contract
Yield farming website is down? Panic is activating? Check this quick and simple guide to bypass the website and interact directly with Tron smart contracts.
- Go to the tronscan website.
- Find the smart contract you want to interact with. Best way is to search for your earlier transaction when you interacted with it.
- On tronscan’s smart contract address go to the contract tab. Here you will have 3 subtabs (Code, Read Contract and Write Contract).
Code
tab is where you can see the contract’s source code if it’s open sourced. Green mark with Contract source code is verified (Perfect match) means that the attached source code matches the contract’s deployed byte codeRead Contract
shows read-only functionsWrite Contract
shows functions that change the state
- Check the
Contract codes
solidity code. This step is to validate that the function you want to call (e.g.exit()
) does want you want it to do. On Tron, the contract can be closed source, meaning that you cannot see the source code files. If you interact with a smart contract without open source code you put all your trust into the person behind it. I recommend to not use any contract that isn’t open source.- a yield farming
exit()
function example from dragonfifunction exit() external { withdraw(balanceOf(msg.sender)); getReward(); }
- the
exit
function calls other 2 methodsfunction withdraw(uint256 amount) public { _totalSupply = _totalSupply.sub(amount); _balances[msg.sender] = _balances[msg.sender].sub(amount); y.safeTransfer(msg.sender, amount); } function getReward() public updateReward(msg.sender) checkhalve checkStart{ uint256 reward = earned(msg.sender); if (reward > 0) { rewards[msg.sender] = 0; dragon.safeTransfer(msg.sender, reward); emit RewardPaid(msg.sender, reward); } }
- if you cannot validate the code, use only audited contracts
- a yield farming
- Then go to the
Write Contract
tab and pressSend
button under the function’s name. It will ask you to connect to your Tronlink wallet to be able to sign the transaction.
Safe Farming!
Tron address: THBW6zVALYiRFi4w8GqD4wFaokZxerV4KT