TRON Developer Hub

The TRON Developer Hub

Welcome to the TRON developer hub. You'll find comprehensive guides and documentation to help you start working with TRON as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

TVM Built-In Functions

Super Node Voting

Address: 0x0000000000000000000000000000000000000000000000000000000000010001;

Input: Super node address, voting count
Output: If command invocation was successful

Solidity Example:

address public voteContractAddress= 0x10001;
/**
 *  @dev   vote for a witness.
 *  @param witnessAddr witness address
 *  @param voteValue the vote amount
 */ 
function voteForSingleWitness (address witnessAddr, uint256 voteValue) public{
    voteContractAddress.delegatecall(witnessAddr,voteValue);
}

Freeze TRX Account

Address: 0x0000000000000000000000000000000000000000000000000000000000010002;

Input: Frozen Amount, Freeze Time Duration
Output: If command invocation was successful

Solidity Example:

//address public freezeBalanceAddress = 0x10002;
/**
 *  don't test now, not support
 *  @dev freeze balance for an account. Should be an normal account, not a contract account.
 */ 
// function freezeBalance(uint256 frozen_Balance,uint256 frozen_Duration) public {
//     freezeBalanceAddress.delegatecall(frozen_Balance,frozen_Duration);
// }

Un-Freeze TRX Account

Address: 0x0000000000000000000000000000000000000000000000000000000000010003;

Input: Frozen Amount, Freeze Time Duration
Output: If command invocation was successful

Solidity Example:

//address public unFreezeBalanceAddress = 0x10003;
/**
 *  don't test now, not support
 *  @dev unFreezeBalance for an account. Should be an normal account, not a contract account.
 */ 
// function unFreezeBalance() public {
//     unFreezeBalanceAddress.delegatecall();
//

Super Node Receives Award

Address: 0x0000000000000000000000000000000000000000000000000000000000010004;

Input: None
Output: If command invocation was successful

Solidity Example:

//address public withdrawBalanceAddress = 0x10004;
/**
 *  @dev   withdraw all rewards for a witness, caller should be witness itself
 */ 
function withdrawBalance() public {
    withdrawBalanceAddress.delegatecall();
}

Super Node Proposal Approval Status

Address: 0x0000000000000000000000000000000000000000000000000000000000010005;

Input: Proposal Vote ID, If Passed or Not
Output: If command invocation was successful

Solidity Example:

address public approveProposalAddress = 0x10005;
/**
 *  @dev   approve a proposal
 *  @param id proposalId
 *  @param isApprove approve or not
 */ 
function approveProposal(uint256 id, bool isApprove) public {
    approveProposalAddress.delegatecall(id,isApprove);
}

Super Node Creation Proposal

Address: 0x0000000000000000000000000000000000000000000000000000000000010006;

Input: Proposal key as a 32 byte array, array size (must be even number), key, value alternate[key1, value1, key2, value2...keyN, valueN]
Output: If command invocation was successful

Solidity Example:

address public createProposalAddress = 0x10006;
/**
 *  @dev create a proposal
 *  @param data bytes32 array of proposal key, value pair (key1,value1,key2,value2....keyN,valueN)
 *  keyi is bytes32
 *  valuei is also bytes32
 */ 
function createProposal(bytes32 [] data) public {
    createProposalAddress.delegatecall(data);
}

Super Node Proposal Deletion

Address: 0x0000000000000000000000000000000000000000000000000000000000010007;

Input: Proposal key as a 32 byte array, array size (must be even number), key, value alternate[key1, value1, key2, value2...keyN, valueN]
Output: If command invocation was successful

Solidity Example:

address public deleteProposalAddress = 0x10007;
/**
 *   @dev for proposal creator to delete a proposal
 *   @param id proposalId
 */ 
function deleteProposal(uint256 id) public{
    deleteProposalAddress.delegatecall(id);
}

Byte Address Conversion into Solidity Address

Address: 0x0000000000000000000000000000000000000000000000000000000000010008;

Input: TRON's 32 byte address
Output: The Solidity Address

Solidity Example:

address public convertFromTronAddress = 0x10008;
/**
 *  @dev convert bytes32 tronAddress to Solidity address type
 *  @param tronAddress bytes32 tronAddress
 *  @return outputAddr Solidity address type
 */
function convertFromTronBytes32Address(bytes32 tronAddress) public view returns(address outputAddr){
    bytes32[1] memory input;
    input[0] = tronAddress;
    address[1] memory output;
    assembly{
            if iszero(call(200, 0x10008, 0, input, 0x20, output, 0x20)) {
                revert(0, 0)
            }
    }
    outputAddr = output[0];
}

String Address Conversion into Solidity Address

Address: 0x0000000000000000000000000000000000000000000000000000000000010009;

Input: TRON's String address
Output: The Solidity Address

Solidity Example:

address public convertFromBase58TronAddress = 0x10009;
 /**
 *  @dev     base58 string tron address to solidity address type
 *  @param   address58 tron address represented as base58 string 
 *  @return  solidity address type
 */
function convertAddress(string address58) public constant returns(address outputAddr){
    bytes32[2] memory input ;
    input[0] = stringToBytes32(substring(address58,0,32));
    input[1] = stringToBytes32(substring(address58,32,34));
    address[1] memory output;
    assembly{
            if iszero(call(200, 0x10009, 0, input, 0x22, output, 0x20)) {
                revert(0, 0)
            }
    }
    outputAddr = output[0];
}

function substring(string str, uint startIndex, uint endIndex) constant returns (string) {
    bytes memory strBytes = bytes(str);
    bytes memory result = new bytes(endIndex-startIndex);
    for(uint i = startIndex; i < endIndex; i++) {
        result[i-startIndex] = strBytes[i];

    }
    return string(result);
}

function stringToBytes32(string str) public constant returns (bytes32 result) {
    string memory source =str ;
    if (bytes(source).length == 0) {
        return 0x0;
    }
    assembly {
        result := mload(add(source, 32))
    }
}

Transferring Tokens to Target Address

Address: 0x000000000000000000000000000000000000000000000000000000000001000a;

Input: Token Transfer Address, Token Transfer Address Size, Token Name
Output: If Token Transfer was Successful

Solidity Example:

address public transferAssetAddress = 0x1000a;
/**
 *  @dev     transferAsset transfer specific number of token asset to targetAddress
 *  @param   toAddress targetAddress transfer token to
 *  @param   amount transfer token amount
 *  @param   name token name
 */
function transferAsset(address toAddress, uint256 amount, string name) public { 
    transferAssetAddress.delegatecall(toAddress,amount,bytes(name));
}

Obtain Target Address Token Balance

Address: 0x000000000000000000000000000000000000000000000000000000000001000b;

Input: Target Token Address, Token Name
Output: Target Address Token Balance Amount

Solidity Example:

address public getTransferAssetBalanceAddress = 0x1000b;
    /**
 *  @dev     getAssetBalance get targetAddress specific token balance
 *  @param   targetAddress current checking address
 *  @param   name token name
 *  @return  token balance for targetAddress
 */
function getAssetBalance(address targetAddress,  string name) public constant returns(uint256 assetBalance) { 
    bytes32 nameBytes32 = stringToBytes32(name);
    assembly{
        let x := mload(0x40)   //Find empty storage location using "free memory pointer"
        mstore(x,targetAddress) //Place first argument directly next to signature
        mstore(add(x,0x20),nameBytes32) //Place second argument next to first, padded to 32 bytes
        if iszero(call(200, 0x1000b, 0, x, 0x40, add(x,0x40), 0x20)) {
            revert(0, 0)
        }
        assetBalance := mload(add(x,0x40)) //Assign output value to assetBalance
        mstore(0x40,add(x,0x60)) // Set storage pointer to empty space
    }
}