TRON Developer Hub CN

TRON开发者中心

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

Get Started    

交换中的TRC10和TRX转移

介绍

在TRON中检测TRX或TRC10事务涉及4种类型的合同:

  • TransferContract(系统合同类型)
  • TransferAssetContract(系统合同类型)
  • CreateSmartContract(智能合约类型)
  • TriggerSmartContract(智能合约类型)

TransactionTransactionInfoBlock 的数据包含所有智能合约交易信息。

检测和记录转移

两个合同 TransferContractTransferAssetContract 分别是用于转移TRX和TRC10的系统合同。事务只包含一个契约,因此查询事务使用接口 GetTransactionbyId 获取有关契约的特定信息。使用GetBlockByNum 来检索打包事务的块信息。旅行 Block 或使用 GetTransactionInfoById 获取特定的交易信息。检查根事务结果。如果 Transaction.Result.code 失败,请拒绝此事务。没有转移。否则,检查 Transaction.raw 中的 type 以获取合同类型信息(TransferContractTransferAssetContract)。检查 Transaction.raw 中的 parameter 以根据 type 获取合同细节。

TransferContract

  • owner_address Bytes)是TRX发件人地址。需要将字节转换为base58Check字符串以显示可读的TRON地址。

  • to_address Bytes)是TRX接收器地址。需要将字节转换为base58Check字符串。

  • amount int64)是发送到合同地址的TRX金额。

TransferAssetContract

  • asset_name String)是TRC10 ID。无需转换即可显示可读的TRON地址。 (此参数用于表示TRC10令牌的名称。在TRON改进建议#14通过以允许相同名称令牌后,此参数已被修改为TRC10 ID)。

  • owner_address Bytes)是TRC10发送方地址。需要将字节转换为base58Check字符串以显示可读的TRON地址。

  • to_address Bytes)是TRC10接收器地址。需要将字节转换为base58Check字符串以显示可读的TRON地址。

  • amount int64)是发送到合同地址的TRC10金额。

CreateSmartContractTriggerSmartContract 的检测类似。使用 GetBlockByNum 来检索打包事务的块信息。旅行 Block 或使用 GetTransactionInfoById 获取特定的交易信息。检查根事务结果。如果 Transaction.Result.code 为 FAILED,则拒绝此事务。没有转移。否则,检查Transaction.raw 中的 type 以获取合同类型信息(CreateSmartContractTriggerSmartContract)。检查 Transaction.raw 中的 parameter 以根据 type 获取合同细节。

CreateSmartContract

  • owner_address Bytes)是TRX或TRC10发送方地址。需要将字节转换为base58Check字符串以显示可读的TRON地址。

  • SmartContract.contract_address Bytes)是TRX或TRC10接收器的地址,它必须是一个智能合约地址。由于在运行时创建,您无法从Transaction中检索它。相反,使用GetTransactionInfoByIdTransactionInfo中获取contract_address。需要将数据从字节转换为base58Check字符串以显示可读的TRON地址。

  • SmartContract.call_value int64)是发送到合同地址的TRX金额。

  • call_token_value int64)是发送到合同地址的TRC10金额。

  • token_id String)是相关的TRC10 ID。转换不需要显示可读的TRON地址。

TriggerSmartContract

  • owner_address Bytes)是TRX或TRC10发送方地址。需要将地址从Bytes转换为base58Check String以显示可读的TRON地址。

  • contract_address Bytes)是TRX或TRC10接收者的地址,它必须是一个智能合约地址。需要将地址从Bytes转换为base58Check String以显示可读的TRON地址。

  • call_value int64)是发送到合同地址的TRX金额。

  • call_token_value int64)是发送到合同地址的TRC10金额。

  • token_id String)是相关的TRC10 ID。

在InternalTransaction中检查转移

  • caller_address Bytes)是TRX或TRC10令牌发送方地址。应将字节转换为base58Check字符串以显示可读的TRON地址。

  • transferTo_address Bytes)是TRX或TRC10令牌接收器地址。应将字节转换为base58Check字符串以显示可读的TRON地址。

  • CallValueInfo是传输详细信息的列表。

  • callvalue int64)代表tokenId为空时的TRX数量。否则,它是令牌传输值。

  • tokenIdString)是令牌标识符。 rejected表示此内部交易是否失败并被拒绝。如果rejected是'true`,则不需要处理当前的内部事务,因为发生了一些错误。否则,值“false”表示成功的事务。

相关Protobuf

TransferContract

message TransferContract {
  bytes owner_address = 1;
  bytes to_address = 2;
  int64 amount = 3;
}

TransferAssetContract

message TransferAssetContract {
  bytes asset_name = 1; // this field is token name before the proposal ALLOW_SAME_TOKEN_NAME is active, otherwise it is token id and token is should be in string format.
  bytes owner_address = 2;
  bytes to_address = 3;
  int64 amount = 4;
}

CreateSmartContract

message CreateSmartContract {
  bytes owner_address = 1;
  SmartContract new_contract = 2;
  int64 call_token_value = 3;
  int64 token_id = 4;
}

TriggerSmartContract

message TriggerSmartContract {
  bytes owner_address = 1;
  bytes contract_address = 2;
  int64 call_value = 3;
  bytes data = 4;
  int64 call_token_value = 5;
  int64 token_id = 6;
}

Transaction

message Transaction {
  message Contract {
    enum ContractType {
      AccountCreateContract = 0;
      TransferContract = 1;
      TransferAssetContract = 2;
      VoteAssetContract = 3;
      VoteWitnessContract = 4;
      WitnessCreateContract = 5;
      AssetIssueContract = 6;
      WitnessUpdateContract = 8;
      ParticipateAssetIssueContract = 9;
      AccountUpdateContract = 10;
      FreezeBalanceContract = 11;
      UnfreezeBalanceContract = 12;
      WithdrawBalanceContract = 13;
      UnfreezeAssetContract = 14;
      UpdateAssetContract = 15;
      ProposalCreateContract = 16;
      ProposalApproveContract = 17;
      ProposalDeleteContract = 18;
      SetAccountIdContract = 19;
      CustomContract = 20;
      // BuyStorageContract = 21;
      // BuyStorageBytesContract = 22;
      // SellStorageContract = 23;
      CreateSmartContract = 30;
      TriggerSmartContract = 31;
      GetContract = 32;
      UpdateSettingContract = 33;
      ExchangeCreateContract = 41;
      ExchangeInjectContract = 42;
      ExchangeWithdrawContract = 43;
      ExchangeTransactionContract = 44;
      UpdateEnergyLimitContract = 45;
      AccountPermissionUpdateContract = 46;
      PermissionAddKeyContract = 47;
      PermissionUpdateKeyContract = 48;
      PermissionDeleteKeyContract = 49;
    }
    ContractType type = 1;
    google.protobuf.Any parameter = 2;
    bytes provider = 3;
    bytes ContractName = 4;
  }

  message Result {
    enum code {
      SUCESS = 0;
      FAILED = 1;
    }
    enum contractResult {
      DEFAULT = 0;
      SUCCESS = 1;
      REVERT = 2;
      BAD_JUMP_DESTINATION = 3;
      OUT_OF_MEMORY = 4;
      PRECOMPILED_CONTRACT = 5;
      STACK_TOO_SMALL = 6;
      STACK_TOO_LARGE = 7;
      ILLEGAL_OPERATION = 8;
      STACK_OVERFLOW = 9;
      OUT_OF_ENERGY = 10;
      OUT_OF_TIME = 11;
      JVM_STACK_OVER_FLOW = 12;
      UNKNOWN = 13;
    }
    int64 fee = 1;
    code ret = 2;
    contractResult contractRet = 3;

    string assetIssueID = 14;
    int64 withdraw_amount = 15;
    int64 unfreeze_amount = 16;
    int64 exchange_received_amount = 18;
    int64 exchange_inject_another_amount = 19;
    int64 exchange_withdraw_another_amount = 20;
    int64 exchange_id = 21;
  }

  message raw {
    bytes ref_block_bytes = 1;
    int64 ref_block_num = 3;
    bytes ref_block_hash = 4;
    int64 expiration = 8;
    repeated authority auths = 9;
    // data not used
    bytes data = 10;
    //only support size = 1,  repeated list here for extension
    repeated Contract contract = 11;
    // scripts not used
    bytes scripts = 12;
    int64 timestamp = 14;
    int64 fee_limit = 18;
  }

  raw raw_data = 1;
  // only support size = 1,  repeated list here for muti-sig extension
  repeated bytes signature = 2;
  repeated Result ret = 5;
}

TransactionInfo

message TransactionInfo {
  enum code {
    SUCESS = 0;
    FAILED = 1;
  }
  message Log {
    bytes address = 1;
    repeated bytes topics = 2;
    bytes data = 3;
  }
  bytes id = 1;
  int64 fee = 2;
  int64 blockNumber = 3;
  int64 blockTimeStamp = 4;
  repeated bytes contractResult = 5;
  bytes contract_address = 6;
  ResourceReceipt receipt = 7;
  repeated Log log = 8;
  code result = 9;
  bytes resMessage = 10;

  string assetIssueID = 14;
  int64 withdraw_amount = 15;
  int64 unfreeze_amount = 16;
  repeated InternalTransaction internal_transactions = 17;
  int64 exchange_received_amount = 18;
  int64 exchange_inject_another_amount = 19;
  int64 exchange_withdraw_another_amount = 20;
  int64 exchange_id = 21;
}

Block

message Block {
  repeated Transaction transactions = 1;
  BlockHeader block_header = 2;
}

交换中的TRC10和TRX转移


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.