TRON Developer Hub CN

TRON开发者中心

欢迎来到TRON开发者中心。您将找到全面的指南和文档,以帮助您尽快开始使用TRON Developer Hub,并在遇到困难时提供支持。让我们跳进去吧!

Get Started    

TVM内置函数

超级节点投票

地址:0x00000000000000000000000000000000000000000000000000000000000000010001;

输入:超级节点地址,表决计数 输出:如果命令调用成功

Solidity示例:

    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);
    }

冻结TRX账户

地址:0x00000000000000000000000000000000000000000000000000000000000000010002;

输入:冻结量,冻结时间持续时间 输出:如果命令调用成功

Solidity示例:

    //address public freezeBalanceAddress = 0x10002;
    /**
     *  don't test now, not support
     *  @dev freeze balance for an account. 应该是普通帐户,而不是合同帐户。
     */ 
    // function freezeBalance(uint256 frozen_Balance,uint256 frozen_Duration) public {
    //     freezeBalanceAddress.delegatecall(frozen_Balance,frozen_Duration);
    // }

取消冻结TRX账户

地址:0x00000000000000000000000000000000000000000000000000000000000000010003;

输入:冻结量,冻结时间持续时间 输出:如果命令调用成功

Solidity示例:

    //address public unFreezeBalanceAddress = 0x10003;
    /**
     *  don't test now, not support
     *  @dev unFreezeBalance for an account. 应该是普通帐户,而不是合同帐户。
     * / 
    // function unFreezeBalance()public {
    // unFreezeBalanceAddress.delegatecall();
    //

超级节点获奖

地址:0x00000000000000000000000000000000000000000000000000000000000000010004;

输入:无 输出:如果命令调用成功

Solidity示例:

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

超级节点提案批准状态

地址:0x00000000000000000000000000000000000000000000000000000000000000010005;

输入:提议投票ID,如果通过或未通过 输出:如果命令调用成功

Solidity示例:

    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);
    }

超级节点创建提案

地址:0x00000000000000000000000000000000000000000000000000000000000000010006;

输入:Proposal键为32字节数组,数组大小(必须为偶数)、键、值交替、[key1,value1,key2,value2... keyN,valueN] 输出:如果命令调用成功

Solidity示例:

    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);
    }

超级节点提议删除

地址:0x0000000000000000000000000000000000000000000000000000000000010007;

输入:Proposal键为32字节数组,数组大小(必须为偶数)、键、值交替、[key1,value1,key2,value2... keyN,valueN] 输出:如果命令调用成功

Solidity示例:

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

字节地址转换为 Solidity 地址

地址:0x00000000000000000000000000000000000000000000000000000000000000010008;

输入:TRON的32字节地址 输出:Solidity地址

Solidity示例:

    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];
    }

字符串地址转换为 Solidity 地址

地址:0x00000000000000000000000000000000000000000000000000000000000000010009;

输入:TRON的字符串地址 输出: Solidity地址

Solidity示例:

    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];
    }

将代币转移到目标地址

地址:0x0000000000000000000000000000000000000000000000000000000000000001000a;

输入:代币转账地址,代币转账地址大小,代币名称 输出:如果代币转账成功

Solidity示例:

    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));
    }

获取目标地址代币余额

地址:0x0000000000000000000000000000000000000000000000000000000000000001000b;

输入:目标代币地址,代币名称 输出:目标地址代币余额金额

Solidity示例:

    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
        }
    }