1、协议接口
1.1 TRC-20 合约标准
TRC-20 是一套发行代币资产的合约标准,按照这套标准编写的合约被视为 TRC-20 合约。钱包和交易所在对接 TRC-20 合约资产时,可以从这套标准中了解合约定义了哪些功能和事件,从而方便对接。
1.1.1 Optional Items
-
Token 名称
string public name = "TRONEuropeRewardCoin";
-
Token 缩写
string public symbol = "TERC";
-
Token 精度(小数)
uint8 public decimals = 6;
1.1.2 Required Items
contract TRC20 {
function totalSupply() constant returns (uint theTotalSupply);
function balanceOf(address _owner) constant returns (uint balance);
function transfer(address _to, uint _value) returns (bool success);
function transferFrom(address _from, address _to, uint _value) returns (bool success);
function approve(address _spender, uint _value) returns (bool success);
function allowance(address _owner, address _spender) constant returns (uint remaining);
event Transfer(address indexed _from, address indexed _to, uint _value);
event Approval(address indexed _owner, address indexed _spender, uint _value);
}
- totalSupply()
该函数返回token
的总供应量。 - balanceOf()
该函数返回特定账户的token
余额。 - transfer()
该函数用于将一定数量的代币转移到指定地址。 - approve()
该函数用于授权第三方(如 DAPP 智能合约)从代币所有者的账户中转移代币。 - transferFrom()
该函数用于允许第三方将代币从所有者账户转移到接收者账户。所有者账户必须获得批准才能被第三方调用。 - allowance()
该函数用于查询第三方可转移的剩余代币数量。
1.1.3 Event Functions
-
token成功转账后,合约将触发转账事件。
event Transfer(address indexed _from, address indexed _to, uint256 _value)
-
成功调用 Approval() 后,合约将触发 Approval 事件。
event Approval(address indexed _owner, address indexed _spender, uint256 _value)
2.2 Contract 案例(源码)
git地址:https://github.com/TRON-Developer-Hub/TRC20-Contract-Template/tree/main
- ITRC20.sol
pragma solidity ^0.5.0;
/**
* @dev Interface of the TRC20 standard as defined in the EIP. Does not include
* the optional functions; to access them see {TRC20Detailed}.
*/
interface ITRC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
}
- SafeMath.sol
pragma solidity ^0.5.0;
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath: division by zero");
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0, "SafeMath: modulo by zero");
return a % b;
}
}
- TRC20.sol
pragma solidity ^0.5.0;
import "./ITRC20.sol";
import "./SafeMath.sol";
/**
* @dev Implementation of the {ITRC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {TRC20Mintable}.
*
* TIP: For a detailed writeup see our guide
* https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* We have followed general OpenZeppelin guidelines: functions revert instead
* of returning `false` on failure. This behavior is nonetheless conventional
* and does not conflict with the expectations of TRC20 applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {ITRC20-approve}.
*/
contract TRC20 is ITRC20 {
using SafeMath for uint256;
mapping (address => uint256) private _balances;
mapping (address => mapping (address => uint256)) private _allowances;
uint256 private _totalSupply;
/**
* @dev See {ITRC20-totalSupply}.
*/
function totalSupply() public view returns (uint256) {
return _totalSupply;
}
/**
* @dev See {ITRC20-balanceOf}.
*/
function balanceOf(address account) public view returns (uint256) {
return _balances[account];
}
/**
* @dev See {ITRC20-transfer}.
*
* Requirements:
*
* - `recipient` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/
function transfer(address recipient, uint256 amount) public returns (bool) {
_transfer(msg.sender, recipient, amount);
return true;
}
/**
* @dev See {ITRC20-allowance}.
*/
function allowance(address owner, address spender) public view returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {ITRC20-approve}.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public returns (bool) {
_approve(msg.sender, spender, value);
return true;
}
/**
* @dev See {ITRC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {TRC20};
*
* Requirements:
* - `sender` and `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `value`.
* - the caller must have allowance for `sender`'s tokens of at least
* `amount`.
*/
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, msg.sender, _allowances[sender][msg.sender].sub(amount));
return true;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {ITRC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].add(addedValue));
return true;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {ITRC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(msg.sender, spender, _allowances[msg.sender][spender].sub(subtractedValue));
return true;
}
/**
* @dev Moves tokens `amount` from `sender` to `recipient`.
*
* This is internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `sender` cannot be the zero address.
* - `recipient` cannot be the zero address.
* - `sender` must have a balance of at least `amount`.
*/
function _transfer(address sender, address recipient, uint256 amount) internal {
require(sender != address(0), "TRC20: transfer from the zero address");
require(recipient != address(0), "TRC20: transfer to the zero address");
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements
*
* - `to` cannot be the zero address.
*/
function _mint(address account, uint256 amount) internal {
require(account != address(0), "TRC20: mint to the zero address");
_totalSupply = _totalSupply.add(amount);
_balances[account] = _balances[account].add(amount);
emit Transfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/
function _burn(address account, uint256 value) internal {
require(account != address(0), "TRC20: burn from the zero address");
_totalSupply = _totalSupply.sub(value);
_balances[account] = _balances[account].sub(value);
emit Transfer(account, address(0), value);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner`s tokens.
*
* This is internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/
function _approve(address owner, address spender, uint256 value) internal {
require(owner != address(0), "TRC20: approve from the zero address");
require(spender != address(0), "TRC20: approve to the zero address");
_allowances[owner][spender] = value;
emit Approval(owner, spender, value);
}
/**
* @dev Destoys `amount` tokens from `account`.`amount` is then deducted
* from the caller's allowance.
*
* See {_burn} and {_approve}.
*/
function _burnFrom(address account, uint256 amount) internal {
_burn(account, amount);
_approve(account, msg.sender, _allowances[account][msg.sender].sub(amount));
}
}
- TRC20Detailed.sol
pragma solidity ^0.5.0;
import "./ITRC20.sol";
/**
* @dev Optional functions from the TRC20 standard.
*/
contract TRC20Detailed is ITRC20 {
string private _name;
string private _symbol;
uint8 private _decimals;
/**
* @dev Sets the values for `name`, `symbol`, and `decimals`. All three of
* these values are immutable: they can only be set once during
* construction.
*/
constructor (string memory name, string memory symbol, uint8 decimals) public {
_name = name;
_symbol = symbol;
_decimals = decimals;
}
/**
* @dev Returns the name of the token.
*/
function name() public view returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5,05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {ITRC20-balanceOf} and {ITRC20-transfer}.
*/
function decimals() public view returns (uint8) {
return _decimals;
}
}
- Token.sol
// 0.5.1-c8a2
// Enable optimization
pragma solidity ^0.5.0;
import "./TRC20.sol";
import "./TRC20Detailed.sol";
/**
* @title SimpleToken
* @dev Very simple TRC20 Token example, where all tokens are pre-assigned to the creator.
* Note they can later distribute these tokens as they wish using `transfer` and other
* `TRC20` functions.
*/
contract Token is TRC20, TRC20Detailed {
/**
* @dev Constructor that gives msg.sender all of existing tokens.
*/
constructor () public TRC20Detailed("YourTokenName", "YTN", 18) {
_mint(msg.sender, 10000000000 * (10 ** uint256(decimals())));
}
}
3 发行 TRC-20 token 教程
-
安装 TronLink 谷歌插件
Address: TronLink -
为发行
token
准备账户
有三种方法创建账户、导入账户和链接硬件钱包。您需要确保账户中有超过 1000 个 TRX。
-
TRC20 合约代码
Trc20 contract template: code
修改 Token.sol 文件,以定义 token name, token symbol, precision, and totalsupply
4. 部署 TRC20 合约
使用 tronscan 进行部署 : deployment tool
- Link wallet
- Compile the contract(编译合约)
Please select 0.5.10 version compiler
出现以下提示,表示编译成功
- Deployment contract(部署合约)
请注意,您必须选择代币合约【Token】,因为代币是主合约
点击确认部署,弹出创联签名对话框,点击接受签名,部署成功后,请获取合同地址,并记录合同地址。
5. 记录 TRC20 Token
使用 Tronscan 进行记录 : Record tool
-
选择 token type
选择 TRC20 token并单击是。 -
输入 TRC20 代币信息
输入token
的基本信息、合同信息和社交媒体信息。带 “*”的字段为必填信息。您输入的信息必须与 TRC20 合同的信息一致。
请注意,必须使用部署者地址登录记录。
- 确认 token 信息
检查token信息是否正确。单击 “我不是机器人”,然后单击 “提交”(注意:此步骤需要 Google 身份验证。中国大陆用户可能需要使用 VPN)。
您将看到一个弹出对话框,确认 token 的发放。点击 “确认”,你将看到 Tronlink 要求你签名的另一个弹出窗口。点击接受,签署信息。
- Token 成功记录
- 添加 tokens to Tronlink
在资产管理页面,在添加 token
输入框中填写部署成功后获得的合约地址,弹出刚刚部署的合约,点击切换按钮,将令牌添加到 tronlink。添加成功后,即可进行转移。
您还可以在 tronscan 上搜索合约主页
注意:
Tronlink 插件目前支持主网和Nile testnet 加令牌。同时,令牌必须在 Tronscan 中成功重新认证,并需要 2 小时的数据同步。
7.确认TRC20 contracts
使用 Tronacan 进行验证: Validation tool
输入合约信息,包括合同地址、合同名称、编译器版本、许可证、优化历史和运行。
合约地址是部署合同时记录的地址。
合约名称指部署的主合同名称。在上面的例子中,名称是 “Token”。
编译器版本为 0.5.10
许可证可以选择 "无
优化历史默认为是,运行次数默认为 0。
单击上传合约文件进行验证。
-
上传合约代码
检查我不是机器人(注意:此步骤需要谷歌验证。中国大陆用户可能需要使用 VPN)。
单击 “验证并发布”,验证成功后,您将进入合约信息页面。 -
合约验证成功
合约信息页面将显示验证成功。
4、TRC-20 合约交换
以 Shasta test net 上的 USDT 合约为例,分别使用 Tronweb 和 wallet-cli 调用合约的 TRC-20 接口。
相关链接
Find the USDT on Tronscan
Code conversion tool
我们可以使用 triggersmartcontract 函数来调用合约中的常量函数,从而直接获得结果,而无需广播。
请在节点配置中设置 supportConstant = true
。
name
调用 name 函数获取token的名称。
- HTTP API :
/wallet/triggerconstantcontract
Description: Trigger the constant of the smart contract, the transaction is off the blockchain
demo: curl -X POST https://127.0.0.1:8090/wallet/triggerconstantcontract -d '{
"contract_address":"419E62BE7F4F103C36507CB2A753418791B1CDC182",
"function_selector":"name()",
"owner_address":"41977C20977F412C2A1AA4EF3D49FEE5EC4C31CDFB"
}'
- Tronweb Example:
const TronWeb = require('tronweb')
const HttpProvider = TronWeb.providers.HttpProvider;
const fullNode = new HttpProvider("https://127.0.0.1:8090");
const solidityNode = new HttpProvider("https://127.0.0.1:8090");
const eventServer = new HttpProvider("https://127.0.0.1:8090");
const privateKey = "your private key";
const tronWeb = new TronWeb(fullNode,solidityNode,eventServer,privateKey);
async function triggerSmartContract() {
const trc20ContractAddress = "TQQg4EL8o1BSeKJY4MJ8TB8XK7xufxFBvK";//contract address
try {
let contract = await tronWeb.contract().at(trc20ContractAddress);
//Use call to execute a pure or view smart contract method.
// These methods do not modify the blockchain, do not cost anything to execute and are also not broadcasted to the network.
let result = await contract.name().call();
console.log('result: ', result);
} catch(error) {
console.error("trigger smart contract error",error)
}
}
- Wallet-cli Example:
TriggerConstantContract TQQg4EL8o1BSeKJY4MJ8TB8XK7xufxFBvK name() # false
使用方法 : TriggerConstantContract [ownerAddress] [contractAddress] [method] [args] [isHex]
参数 描述:
- ownerAddress: 调用者 address
- contractAdress:TRC20 合约地址
- method: 合约函数
- args:函数参数,如果没有参数,则使用 # 占位符
- isHex:命令参数的地址是否为十六进制格式
symbol
调用symbol函数获取标记的symbol。
/wallet/triggerconstantcontract
Description: Trigger the constant of the smart contract, the transaction is off the blockchain
demo: curl -X POST https://127.0.0.1:8090/wallet/triggerconstantcontract -d '{
"contract_address":"419E62BE7F4F103C36507CB2A753418791B1CDC182",
"function_selector":"symbol()",
"owner_address":"41977C20977F412C2A1AA4EF3D49FEE5EC4C31CDFB"
}'
- Tronweb Example:
const TronWeb = require('tronweb')
const HttpProvider = TronWeb.providers.HttpProvider;
const fullNode = new HttpProvider("https://127.0.0.1:8090");
const solidityNode = new HttpProvider("https://127.0.0.1:8090");
const eventServer = new HttpProvider("https://127.0.0.1:8090");
const privateKey = "your private key";
const tronWeb = new TronWeb(fullNode,solidityNode,eventServer,privateKey);
async function triggerSmartContract() {
const trc20ContractAddress = "TQQg4EL8o1BSeKJY4MJ8TB8XK7xufxFBvK";//contract address
try {
let contract = await tronWeb.contract().at(trc20ContractAddress);
//Use call to execute a pure or view smart contract method.
// These methods do not modify the blockchain, do not cost anything to execute and are also not broadcasted to the network.
let result = await contract.symbol().call();
console.log('result: ', result);
} catch(error) {
console.error("trigger smart contract error",error)
}
}
- Wallet-cli Example:
TriggerConstantContract TQQg4EL8o1BSeKJY4MJ8TB8XK7xufxFBvK symbol() # false
使用方法 : TriggerConstantContract [ownerAddress] [contractAddress] [method] [args] [isHex]
参数描述:
ownerAddress: 调用者地址
contractAdress:合约地址
method: 合约函数
args:函数参数 # placeholder
isHex: 命令参数的地址是否为十六进制格式
-
decimals
调用小数点功能获取标记的精度。
HTTP API :
/wallet/triggerconstantcontract Description: Trigger the constant of the smart contract, the transaction is off the blockchain demo: curl -X POST https://127.0.0.1:8090/wallet/triggerconstantcontract -d '{ "contract_address":"419E62BE7F4F103C36507CB2A753418791B1CDC182", "function_selector":"decimals()", "owner_address":"41977C20977F412C2A1AA4EF3D49FEE5EC4C31CDFB" }'
-
totalSupply
调用 totalSupply 函数获取令牌的总供应量。
HTTP API :
/wallet/triggerconstantcontract
Description: Trigger the constant of the smart contract, the transaction is off the blockchain
demo: curl -X POST https://127.0.0.1:8090/wallet/triggerconstantcontract -d '{
"contract_address":"419E62BE7F4F103C36507CB2A753418791B1CDC182",
"function_selector":"totalSupply()",
"owner_address":"41977C20977F412C2A1AA4EF3D49FEE5EC4C31CDFB"
}'
-
balanceOf
调用 balanceOf 函数获取指定账户的令牌余额。
HTTP API :/wallet/triggerconstantcontract Description: Trigger the constant of the smart contract, the transaction is off the blockchain demo: curl -X POST https://127.0.0.1:8090/wallet/triggerconstantcontract -d '{ "contract_address":"419E62BE7F4F103C36507CB2A753418791B1CDC182", "function_selector":"balanceOf(address)", "parameter":"000000000000000000000041977C20977F412C2A1AA4EF3D49FEE5EC4C31CDFB", "owner_address":"41977C20977F412C2A1AA4EF3D49FEE5EC4C31CDFB" }'
-
transfer
token转账功能
wallet/triggersmartcontract Description: Trigger smart contract demo: curl -X POST https://127.0.0.1:8090/wallet/triggersmartcontract -d '{ "contract_address":"419E62BE7F4F103C36507CB2A753418791B1CDC182", "function_selector":"transfer(address,uint256)", "parameter":"00000000000000000000004115208EF33A926919ED270E2FA61367B2DA3753DA0000000000000000000000000000000000000000000000000000000000000032", "fee_limit":100000000, "call_value":0, "owner_address":"41977C20977F412C2A1AA4EF3D49FEE5EC4C31CDFB" }'
-
approve
调用 approve 函数授权其他地址一定数量的令牌使用权。
wallet/triggersmartcontract Description: Trigger smart contract demo: curl -X POST https://127.0.0.1:8090/wallet/triggersmartcontract -d '{ "contract_address":"419E62BE7F4F103C36507CB2A753418791B1CDC182", "function_selector":"approve(address,uint256)", "parameter":"0000000000000000000000410FB357921DFB0E32CBC9D1B30F09AAD13017F2CD0000000000000000000000000000000000000000000000000000000000000064", "fee_limit":100000000, "call_value":0, "owner_address":"41977C20977F412C2A1AA4EF3D49FEE5EC4C31CDFB" }'
-
transferFrom
授权地址调用 transferFrom 函数从授权者转移token。
wallet/triggersmartcontract Description: Trigger smart contract demo: curl -X POST https://127.0.0.1:8090/wallet/triggersmartcontract -d '{ "contract_address":"419E62BE7F4F103C36507CB2A753418791B1CDC182", "function_selector":"transferFrom(address,address,uint256)", "parameter":"00000000000000000000004109669733965A37BA3582E70CCC5302F8D254675D0000000000000000000000410FB357921DFB0E32CBC9D1B30F09AAD13017F2CD0000000000000000000000000000000000000000000000000000000000000032", "fee_limit":100000000, "call_value":0, "owner_address":"41977C20977F412C2A1AA4EF3D49FEE5EC4C31CDFB" }'
-
allowance
授权地址调用查询被授权金额余额。
/wallet/triggerconstantcontract Description: Trigger the constant of the smart contract, the transaction is off the blockchain demo: curl -X POST https://127.0.0.1:8090/wallet/triggersmartcontract -d '{ "contract_address":"419E62BE7F4F103C36507CB2A753418791B1CDC182", "function_selector":"allowance(address,address)", "parameter":"00000000000000000000004109669733965A37BA3582E70CCC5302F8D254675D000000000000000000000041A245B99ECB47B18C6A90ED1D51100C5A9F0641A7", "owner_address":"41977C20977F412C2A1AA4EF3D49FEE5EC4C31CDFB" }'
5 、Get TRC-20 transaction history
获取指定账户中指定 TRC-20 的交易历史记录。
API documents references
-
Get TRC-20 transaction info by account address
curl --request GET \ --url 'https://api.trongrid.io/v1/accounts/TJmmqjb1DK9TTZbQXzRQ2AuA94z4gKAPFh/transactions/trc20?limit=100&contract_address=TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t' Parameters: version:The latest version v1. address: account address,in Base58 or Hex. only_confirmed: true|false. if false, returns both confirmed & unconfirmed transactions; if no parameters, returns both confirmed & unconfirmed transactions. CAN NOT be used with only_unconfirmed. only_unconfirmed: true|false. if false,returns both confirmed & unconfirmed transactions; if no parameters, returns both confirmed & unconfirmed transactions. CAN NOT be used with only_confirmed. limit:transactions per page,default is 20, maximum is 200. fingerprint:The fingerprint of the last transaction returned on the previous page . When using this, other parameters and filters should remain unchanged. contract_address:TRC20 contract address, Base58 or Hex. //Example //Get transactions related to TRC20 USDT on the address TJmmqjb1DK9TTZbQXzRQ2AuA94z4gKAPFh curl --request GET \ --url ' https://api.trongrid.io/v1/accounts/TJmmqjb1DK9TTZbQXzRQ2AuA94z4gKAPFh/transactions/trc20?limit=20&contract_address=TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'