Validate an attached TRC-10 deposit inside a TRON contract

TRC-10 units can arrive as native transaction attachments. A contract that credits the amount without verifying the attached token ID can accept a different asset under the same deposit path.

Inspect the TVM attachment fields

In a contract compiled with TRON’s Solidity compiler, keep acceptedToken as the configured trcToken and credit as your accounting mapping. The excerpt requires positive units of that exact TRC-10 and rejects unexpected native TRX.

function deposit() external payable {
    require(msg.tokenid == acceptedToken, "asset");
    require(msg.tokenvalue > 0, "empty");
    require(msg.value == 0, "unexpected TRX");
    credit[msg.sender] += msg.tokenvalue;
}

Exercise the wrong-token path

Send a local test call with ten units of a different token ID and assert that credit remains unchanged. Then repeat with ten units of the configured ID and verify the ledger delta. A TRC-20 deposit uses smart-contract calls and needs a different integration. Testing only a TRC-20 transfer event never exercises this native TRC-10 attachment.

Sources