diff --git a/SUMMARY.md b/SUMMARY.md index 935ea0f..6a76c87 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -75,6 +75,14 @@ * [Other TRC-10 Interfaces](networks/tron-network/trx-and-trc-token/trc-10/other-trc-10-interfaces.md) * [TRC-20](networks/tron-network/trx-and-trc-token/trc-20/README.md) * [Protocol Interface](networks/tron-network/trx-and-trc-token/trc-20/protocol-interface.md) + * [Issuing TRC-20 tokens tutorial](networks/tron-network/trx-and-trc-token/trc-20/issuing-trc-20-tokens-tutorial.md) + * [TRC-20 Contract Interaction](networks/tron-network/trx-and-trc-token/trc-20/trc-20-contract-interaction.md) + * [TRC-20 Event Listener](networks/tron-network/trx-and-trc-token/trc-20/trc-20-event-listener.md) + * [TRC-20 transaction history](networks/tron-network/trx-and-trc-token/trc-20/trc-20-transaction-history.md) + * [TRC-721](networks/tron-network/trx-and-trc-token/trc-721/README.md) + * [TRC-721 Token Issuance](networks/tron-network/trx-and-trc-token/trc-721/trc-721-token-issuance.md) + * [TRC-721 Contract Interaction](networks/tron-network/trx-and-trc-token/trc-721/trc-721-contract-interaction.md) + * [Uploading NFT Metadata to BTFS Network](networks/tron-network/trx-and-trc-token/trc-721/uploading-nft-metadata-to-btfs-network.md) * [Ethereum \(ERC\)](networks/ethereum-erc/README.md) * [Ether - Introduction](networks/ethereum-erc/ether-introduction/README.md) * [The Ethereum Foundation](networks/ethereum-erc/ether-introduction/the-ethereum-foundation.md) diff --git a/networks/tron-network/trx-and-trc-token/trc-20/issuing-trc-20-tokens-tutorial.md b/networks/tron-network/trx-and-trc-token/trc-20/issuing-trc-20-tokens-tutorial.md new file mode 100644 index 0000000..c9d15bd --- /dev/null +++ b/networks/tron-network/trx-and-trc-token/trc-20/issuing-trc-20-tokens-tutorial.md @@ -0,0 +1,96 @@ +# Issuing TRC-20 tokens tutorial + +## 1. Install TronLink Chrome plugin + +Address: [TronLink](https://chrome.google.com/webstore/detail/tronlink%EF%BC%88%E6%B3%A2%E5%AE%9D%E9%92%B1%E5%8C%85%EF%BC%89/ibnejdfjmmkpcnlpebklmnkoeoihofec) + +### **2. Prepare an account for issue token** + +There are three ways to _create an account_, _import an account_, and _link a hardware wallet._ You need to ensure that there are more than 1000 TRX in the account.![](https://files.readme.io/f4260b0-_1.png)![](https://files.readme.io/f4260b0-_1.png) + +### **3. Prepare the TRC20 contract code** + +Trc20 contract template: [code](https://github.com/zyumingfit/TRC20-Contract-Template) + +Modify the Token.sol file to define the **token name,** **token symbol**, **precision**, and **totalsupply**![](https://files.readme.io/051aee0-_1.png)![](https://files.readme.io/051aee0-_1.png) + +### **4. Deploy TRC20 contract** + +Deploy with tronscan: [deployment tool](https://tronscan.io/#/contracts/contract-compiler) + +* Link wallet + +![](https://files.readme.io/5c3df2f-_2020-08-21_12.15.55.png)![](https://files.readme.io/5c3df2f-_2020-08-21_12.15.55.png) + +* Upload contract code + +![](https://files.readme.io/9118251-_1.png)![](https://files.readme.io/9118251-_1.png)![](https://files.readme.io/e124c71-_1.png)![](https://files.readme.io/e124c71-_1.png) + +* Compile the contract Please select 0.5.10 version compiler + +![](https://files.readme.io/9ec0d79-_1.png)![](https://files.readme.io/9ec0d79-_1.png)![](https://files.readme.io/ca81448-_1.png)![](https://files.readme.io/ca81448-_1.png) + +The following prompt appears, indicating successful compilation![](https://files.readme.io/7a87419-_1.png)![](https://files.readme.io/7a87419-_1.png) + +* Deployment contract + +Please note that you must choose the Token contract, because Token is the main contract![](https://files.readme.io/5096e27-_1.png)![](https://files.readme.io/5096e27-_1.png) + +Click Confirm to deploy, the tronlink signature dialog box will pop up, click to accept to sign,when successful deployment, please get the contract address, and record the contract address.![](https://files.readme.io/956aadd-WX20200821-1210532x.png)![](https://files.readme.io/956aadd-WX20200821-1210532x.png)![](https://files.readme.io/42e3cde-_1.png)![](https://files.readme.io/42e3cde-_1.png) + +### **5. Add tokens to Tronlink** + +On the asset management page, fill in the contract address obtained after successful deployment in the add token input box, the contract just deployed will pop up, click the switch button, and add the token to tronlink. After the addition is successful, the transfer can be carried out.![](https://files.readme.io/26beafe-_1.png)![](https://files.readme.io/26beafe-_1.png) + +You can also search the contract homepage on tronscan![](https://files.readme.io/180b061-_1.png)![](https://files.readme.io/180b061-_1.png) + +### **6.Verify TRC20 contracts** + +Verify with Tronacan: [Validation tool](https://tronscan.org/#/contracts/verify) + +* Enter contract information including contract address,contract name, compiler version, License, optimization history and Runs. + +Contract address is the address recorded while deploying the contract. +Contract name refers to the name of the main contract deployed. In the example above, the name is "Token". +Compiler version is 0.5.10 +You may select None for License +Optimization history is Yes and Runs is 0 by default.![](https://files.readme.io/54a2b0b-11.png)![](https://files.readme.io/54a2b0b-11.png) + +Click Upload contract file\(s\) for validation. + +* Upload contract code Check I am not a robot \(Note: Google authentication is required for this step. Users in Mainland China may have to use VPN\). + +![](https://files.readme.io/4106456-12.png)![](https://files.readme.io/4106456-12.png) + +Click Verify and publish, you will be directed to the contract information page once validated successfully. + +* Contract successfully validated Contract information page will show successful validation. + +![](https://files.readme.io/842e8d2-13.png)![](https://files.readme.io/842e8d2-13.png) + +### **7. Record TRC20 Token** + +Record with Tronscan: [Record tool](https://tronscan.org/#/tokens/create/Type) + +* Select token type + +![](https://files.readme.io/19aa7aa-14.png)![](https://files.readme.io/19aa7aa-14.png) + +Select the TRC20 token and click Yes. + +* Enter TRC20 token information Enter the basic information, contract information and social media information of the token. Fields with "\*" are required information. The information you entered must match that of the TRC20 contract. Please note that record must be logged in with the deployer address. + +![](https://files.readme.io/152689c-15.png)![](https://files.readme.io/152689c-15.png) + +Enter all information required for the TRC20 token, click Next.![](https://files.readme.io/e27e3d2-16.png)![](https://files.readme.io/e27e3d2-16.png) + +* Confirm token information + +Check if token information is right. Click I’m not a robot, and then click Submit \(Note: Google authentication is required for this step. Users in Mainland China may have to use VPN\).![](https://files.readme.io/d8a03d1-17.png)![](https://files.readme.io/d8a03d1-17.png) + +You will see a popup dialog to confirm token issuance. Click Confirm and you will see another popup from Tronlink asking for your signature. Click Accept to sign the message.![](https://files.readme.io/5ba592e-18.png)![](https://files.readme.io/5ba592e-18.png) + +* Token successfully recorded + +![](https://files.readme.io/c476df0-19.png) + diff --git a/networks/tron-network/trx-and-trc-token/trc-20/trc-20-contract-interaction.md b/networks/tron-network/trx-and-trc-token/trc-20/trc-20-contract-interaction.md new file mode 100644 index 0000000..19c7a26 --- /dev/null +++ b/networks/tron-network/trx-and-trc-token/trc-20/trc-20-contract-interaction.md @@ -0,0 +1,589 @@ +# TRC-20 Contract Interaction + +Take the USDT contract on Shasta test net as an example,Use Tronweb and wallet-cli to call the TRC-20 interface of the contract, respectively. + +Some related links: +[Find the USDT on Tronscan](https://shasta.tronscan.org/#/contract/TQQg4EL8o1BSeKJY4MJ8TB8XK7xufxFBvK/code) +[Code conversion tool](https://shasta.tronscan.org/#/tools/tron-convert-tool) + +We can use the `triggersmartcontract` function to call constant functions in the contract to get the result directly without broadcasting. +Please set `supportConstant` = true in your node config. + +## name + +Call the name function to get the name of the token. + +**HTTP API :**HTTP + +```text +/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:**JavaScript + +```text +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:**wallet-cli command + +```text +TriggerConstantContract TQQg4EL8o1BSeKJY4MJ8TB8XK7xufxFBvK name() # false +``` + +**Usage :** TriggerConstantContract \[ownerAddress\] \[contractAddress\] \[method\] \[args\] \[isHex\] +**Parameter Description:** +ownerAddress: calller address +contractAdress:TRC20 contract address +method: contract function +args:function parameters,If there is no parameter,use \# placeholder +isHex: whether the address of the command parameter is in hex format + +## symbol + +Call the symbol function to get the symbol of the token. + +**HTTP API :**HTTP + +```text +/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:**JavaScript + +```text +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:**wallet-cli command + +```text +TriggerConstantContract TQQg4EL8o1BSeKJY4MJ8TB8XK7xufxFBvK symbol() # false +``` + +**Usage :** TriggerConstantContract \[ownerAddress\] \[contractAddress\] \[method\] \[args\] \[isHex\] +**Parameter Description:** +ownerAddress: calller address +contractAdress:TRC20 contract address +method: contract function +args:function parameters,If there is no parameter,use \# placeholder +isHex: whether the address of the command parameter is in hex format + +## decimals + +Call the decimals function to get the precision of the token. + +**HTTP API :**HTTP + +```text +/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" +}' +``` + +**Tronweb Example:**JavaScript + +```text +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.decimals().call(); + console.log('result: ', result); + } catch(error) { + console.error("trigger smart contract error",error) + } +} +``` + +**Wallet-cli Example:**wallet-cli command + +```text +TriggerConstantContract TQQg4EL8o1BSeKJY4MJ8TB8XK7xufxFBvK decimals() # false +``` + +**Usage :** TriggerConstantContract \[ownerAddress\] \[contractAddress\] \[method\] \[args\] \[isHex\] +**Parameter Description:** +ownerAddress: calller address +contractAdress:TRC20 contract address +method: contract function +args:function parameters,If there is no parameter,use \# placeholder +isHex: whether the address of the command parameter is in hex format + +## totalSupply + +Call the totalSupply function to get the total supply of the token. + +**HTTP API :**HTTP + +```text +/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" +}' +``` + +**Tronweb Example:**JavaScript + +```text +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.totalSupply().call(); + console.log('result: ', result); + } catch(error) { + console.error("trigger smart contract error",error) + } +} +``` + +**Wallet-cli:**wallet-cli command + +```text +TriggerConstantContract TQQg4EL8o1BSeKJY4MJ8TB8XK7xufxFBvK totalSupply() # false +``` + +**Usage :** TriggerConstantContract \[ownerAddress\] \[contractAddress\] \[method\] \[args\] \[isHex\] +**Parameter Description:** +ownerAddress: calller address +contractAdress:TRC20 contract address +method: contract function +args:function parameters,If there is no parameter,use \# placeholder +isHex: whether the address of the command parameter is in hex format + +## balanceOf + +Call the balanceOf function to get the token balance of the specified account. + +**HTTP API :**HTTP + +```text +/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" +}' +``` + +**Tronweb Example:**JavaScript + +```text +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 + var address = "TM2TmqauSEiRf16CyFgzHV2BVxBe..."; + + 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.balanceOf(address).call(); + console.log('result: ', result); + } catch(error) { + console.error("trigger smart contract error",error) + } +} +``` + +**Wallet-cli Example:**wallet-cli command + +```text +TriggerConstantContract TQQg4EL8o1BSeKJY4MJ8TB8XK7xufxFBvK balanceOf(address) "TM2TmqauSEiRf16CyFgzHV2BVxBejY9iyR" false +``` + +**Usage :** TriggerConstantContract \[ownerAddress\] \[contractAddress\] \[method\] \[args\] \[isHex\] +**Parameter Description:** +ownerAddress: calller address +contractAdress:TRC20 contract address +method: contract function +args:function parameters,If there is no parameter,use \# placeholder +isHex: whether the address of the command parameter is in hex format + +## transfer + +Call transfer function for token transfer + +**HTTP API :**HTTP + +```text +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" +}' +``` + +The parameter is to encode address and uint256 in transfer \(address,uint256\), please refer to [the parameter encoding and decoding document](https://developers.tron.network/docs/parameter-and-return-value-encoding-and-decoding) +Note: After calling this HTTP API, you also need to call the signature and broadcast APIs. + +**Tronweb Example:**JavaScript + +```text +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 + var address = "TM2TmqauSEiRf16CyFgzHV2BVxBe..."; + + try { + let contract = await tronWeb.contract().at(trc20ContractAddress); + //Use send to execute a non-pure or modify smart contract method on a given smart contract that modify or change values on the blockchain. + // These methods consume resources(bandwidth and energy) to perform as the changes need to be broadcasted out to the network. + let result await contract.transfer( + "TVDGp...", //address _to + 1000000 //amount + ).send({ + feeLimit: 1000000 + }).then(output => {console.log('- Output:', output, '\n');}); + console.log('result: ', result); + } catch(error) { + console.error("trigger smart contract error",error) + } +} +``` + +**Wallet-cli Example:**wallet-cli command + +```text +TriggerContract TQQg4EL8o1BSeKJY4MJ8TB8XK7xufxFBvK transfer(address,uint256) "TBQDyqoJ2ZJHTRDsrGQasyqBm4nUVLbWee",100 false 100000000 0 0 # +``` + +**Usage :** +TriggerContract \[ownerAddress\] \[contractAddress\] \[method\] \[args\] \[isHex\] \[fee\_limit\] \[value\] \[token\_value\] \[token\_id\] +**Parameter Description:** +ownerAddress: calller address +contractAdress:TRC20 contract address +method: contract function +args:function parameters,If there is no parameter,use \# placeholder +isHex: whether the address of the command parameter is in hex format +fee\_limit: the maximum trx consumption of this calling, the unit is sun +value: the amount of TRX that transfered to the contract while calling the contract, the unit is sun +token\_value: the amount of TRC10 asset that transfered to the contract while calling the contract +token\_id:the TRC10 asset ID that transfered to the contract while calling the contract + +Transaction confirmation: +Check whether the transfer of TRC20 was successful according to result of getTransactionInfoById. + +## approve + +Call the approve function to authorize token use rights to other addresses + +**HTTP API :**HTTP + +```text +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" +}' +``` + +Note: After calling this HTTP API, you also need to call the signature and broadcast APIs. + +**Tronweb Example:**JavaScript + +```text +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() { + //User A allows user B to use 10USDT of A: A calls approve (B,10) + const trc20ContractAddress = "TQQg4EL8o1BSeKJY4MJ8TB8XK7xufxFBvK";//contract address + + try { + let contract = await tronWeb.contract().at(trc20ContractAddress); + //Use send to execute a non-pure or modify smart contract method on a given smart contract that modify or change values on the blockchain. + // These methods consume resources(bandwidth and energy) to perform as the changes need to be broadcasted out to the network. + await contract.approve( + "TA1g2WQiXbU...", //address _spender + 10000000 //amount + ).send({ + feeLimit: 100000000 + }).then(output => {console.log('- Output:', output, '\n');}); + } catch(error) { + console.error("trigger smart contract error",error) + } +} +``` + +**Wallet-cli Example:**wallet-cli command + +```text +TriggerContract TQQg4EL8o1BSeKJY4MJ8TB8XK7xufxFBvK approve(address,uint256) "TBQDyqoJ2ZJHTRDsrGQasyqBm4nUVLbWee",100 false 100000000 0 0 # +``` + +**Usage :** +TriggerContract \[ownerAddress\] \[contractAddress\] \[method\] \[args\] \[isHex\] \[fee\_limit\] \[value\] \[token\_value\] \[token\_id\] +**Parameter Description:** +ownerAddress: calller address +contractAdress:TRC20 contract address +method: contract function +args:function parameters,If there is no parameter,use \# placeholder +isHex: whether the address of the command parameter is in hex format +fee\_limit: the maximum trx consumption of this calling, the unit is sun +value: the amount of TRX that transfered to the contract while calling the contract, the unit is sun +token\_value: the amount of TRC10 asset that transfered to the contract while calling the contract +token\_id:the TRC10 asset ID that transfered to the contract while calling the contract + +Transaction confirmation: +Check whether the transfer of TRC20 was successful according to result of getTransactionInfoById. + +## transferFrom + +Calling the transferFrom function to transfer tokens from other people's accounts, needs to be used in conjunction with the approve method. + +**HTTP API :**HTTP + +```text +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" +}' +``` + +Note: After calling this HTTP API, you also need to call the signature and broadcast APIs. + +**Tronweb Example:**JavaScript + +```text +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() { + // Address B transfers 10 USDT from address A to C: B calls transferFrom (A, C, 10) + const trc20ContractAddress = "TQQg4EL8o1BSeKJY4MJ8TB8XK7xufxFBvK";//contract address + + try { + let contract = await tronWeb.contract().at(trc20ContractAddress); + //Use send to execute a non-pure or modify smart contract method on a given smart contract that modify or change values on the blockchain. + // These methods consume resources(bandwidth and energy) to perform as the changes need to be broadcasted out to the network. + await contract.transferFrom( + "TM2TmqauSEiRf16CyFgzHV2BVxBej...", //address _from + "TVDGpn4hCSzJ5nkHPLetk8KQBtwaT...", //address _to + 100000 //amount + ).send({ + feeLimit: 10000000 + }).then(output => {console.log('- Output:', output, '\n');}); + } catch(error) { + console.error("trigger smart contract error",error) + } +} +``` + +**Wallet-cli Example:**wallet-cli command + +```text +TriggerContract TQQg4EL8o1BSeKJY4MJ8TB8XK7xufxFBvK transferFrom(address,address,uint256) "TApuyuazZnGgxvbNbaGcrUijEFn1oidsAH","TBQDyqoJ2ZJHTRDsrGQasyqBm4nUVLbWee",50 false 100000000 0 0 # +``` + +**Usage :** +TriggerContract \[ownerAddress\] \[contractAddress\] \[method\] \[args\] \[isHex\] \[fee\_limit\] \[value\] \[token\_value\] \[token\_id\] +**Parameter Description:** +ownerAddress: calller address +contractAdress:TRC20 contract address +method: contract function +args:function parameters,If there is no parameter,use \# placeholder +isHex: whether the address of the command parameter is in hex format +fee\_limit: the maximum trx consumption of this calling, the unit is sun +value: the amount of TRX that transfered to the contract while calling the contract, the unit is sun +token\_value: the amount of TRC10 asset that transfered to the contract while calling the contract +token\_id:the TRC10 asset ID that transfered to the contract while calling the contract + +Transaction confirmation: +Check whether the transfer of TRC20 was successful according to result of getTransactionInfoById. + +## allowance + +Call the allowance function to query the token balance of the query account available for third-party transfers. + +**HTTP API :**HTTP + +```text +/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" +}' +``` + +**Tronweb Example:**JavaScript + +```text +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() { + //Query the USDT balance that Account A can use for Account B: Account B calls allowance (A, B) + const trc20ContractAddress = "TQQg4EL8o1BSeKJY4MJ8TB8XK7xufxFBvK";//contract address + + try { + let contract = await tronWeb.contract().at(trc20ContractAddress); + //Use send to execute a non-pure or modify smart contract method on a given smart contract that modify or change values on the blockchain. + // These methods consume resources(bandwidth and energy) to perform as the changes need to be broadcasted out to the network. + const value = await contract.allowance( + "TM2TmqauSEiRf16CyFgzHV2BVxBejY9...", //address _owner + "TA1g2WQiXbU5GnYBTJ5Cp22dvSjT3ug..." //address _spender + ).call(); + console.log('- Output:', value, '\n'); + } catch(error) { + console.error("trigger smart contract error",error) + } +} +``` + +**Wallet-cli Example:**wallet-cli command + +```text +TriggerConstantContract TQQg4EL8o1BSeKJY4MJ8TB8XK7xufxFBvK allowance(address,address) "TApuyuazZnGgxvbNbaGcrUijEFn1oidsAH","TQmDzierQxEFJm1dT5YXnTXqVAfdN9HtXj" false +``` + +**Usage :** TriggerConstantContract \[ownerAddress\] \[contractAddress\] \[method\] \[args\] \[isHex\] +**Parameter Description:** +ownerAddress: calller address +contractAdress:TRC20 contract address +method: contract function +args:function parameters,If there is no parameter,use \# placeholder +isHex: whether the address of the command parameter is in hex format + + diff --git a/networks/tron-network/trx-and-trc-token/trc-20/trc-20-event-listener.md b/networks/tron-network/trx-and-trc-token/trc-20/trc-20-event-listener.md new file mode 100644 index 0000000..34d9945 --- /dev/null +++ b/networks/tron-network/trx-and-trc-token/trc-20/trc-20-event-listener.md @@ -0,0 +1,25 @@ +# TRC-20 Event Listener + +Use Tronweb's `watch` method to listen to events emitted by the smart contract method. You can set a callback function to handle the event. When the event occurs, the callback function will be triggered. The following example listens to the transfer event of the USDT-TRC20 contract of the MainNet. + +**Tronweb Example:**JavaScript + +```text +const trc20ContractAddress = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"; //mainnet USDT contract +let contract = await tronWeb.contract().at(trc20ContractAddress); + +//contract.[eventname].watch(callback) enventname is the name of the event of the contract +await contract && contract.Transfer().watch((err, event) => { + if(err) + return console.error('Error with "Message" event:', err); + + console.group('New event received'); + console.log('- Contract Address:', event.contract); + console.log('- Event Name:', event.name); + console.log('- Transaction:', event.transaction); + console.log('- Block number:', event.block); + console.log('- Result:', event.result, '\n'); + console.groupEnd(); +}); +``` + diff --git a/networks/tron-network/trx-and-trc-token/trc-20/trc-20-transaction-history.md b/networks/tron-network/trx-and-trc-token/trc-20/trc-20-transaction-history.md new file mode 100644 index 0000000..f16d1dd --- /dev/null +++ b/networks/tron-network/trx-and-trc-token/trc-20/trc-20-transaction-history.md @@ -0,0 +1,33 @@ +# TRC-20 transaction history + +## Get TRC-20 transaction history + +**Get the transaction history for a specific TRC-20 in a specific account.** + +API documents references + +* [Get Transaction history](https://developers.tron.network/docs/get-history) +* [Get TRC-20 transaction info by account address](https://developers.tron.network/reference-link/trc20-transaction-information-by-account-address) + +Shell + +```text +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' +``` + diff --git a/networks/tron-network/trx-and-trc-token/trc-721/README.md b/networks/tron-network/trx-and-trc-token/trc-721/README.md new file mode 100644 index 0000000..c5f3a22 --- /dev/null +++ b/networks/tron-network/trx-and-trc-token/trc-721/README.md @@ -0,0 +1,132 @@ +# TRC-721 + +## TRC-721 Protocol Standard + +TRC-721 is a set of standard interfaces, for issuing non-fungible tokens\(NFT\) on the TRON network. TRC-721 is fully compatible with ERC-721. + +### TRC-721 Smart Contract Interface Implementation + +Every TRC-721 compliant contract must implement the TRC721 and TRC165 interfaces. Other extension interfaces can be implemented according to specific business requirements. + +#### TRC-721 & TRC-165 Interfaces + +Solidity + +```text +pragma solidity ^0.4.20; + + interface TRC721 { + // Returns the number of NFTs owned by the given account + function balanceOf(address _owner) external view returns (uint256); + + //Returns the owner of the given NFT + function ownerOf(uint256 _tokenId) external view returns (address); + + //Transfer ownership of NFT + function safeTransferFrom(address _from, address _to, uint256 _tokenId, bytes data) external payable; + + //Transfer ownership of NFT + function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable; + + //Transfer ownership of NFT + function transferFrom(address _from, address _to, uint256 _tokenId) external payable; + + //Grants address ‘_approved’ the authorization of the NFT ‘_tokenId’ + function approve(address _approved, uint256 _tokenId) external payable; + + //Grant/recover all NFTs’ authorization of the ‘_operator’ + function setApprovalForAll(address _operator, bool _approved) external; + + //Query the authorized address of NFT + function getApproved(uint256 _tokenId) external view returns (address); + + //Query whether the ‘_operator’ is the authorized address of the ‘_owner’ + function isApprovedForAll(address _owner, address _operator) external view returns (bool); + + //The successful ‘transferFrom’ and ‘safeTransferFrom’ will trigger the ‘Transfer’ Event + event Transfer(address indexed _from, address indexed _to, uint256 indexed _tokenId); + + //The successful ‘Approval’ will trigger the ‘Approval’ event + event Approval(address indexed _owner, address indexed _approved, uint256 indexed _tokenId); + + //The successful ‘setApprovalForAll’ will trigger the ‘ApprovalForAll’ event + event ApprovalForAll(address indexed _owner, address indexed _operator, bool _approved); + + } + + interface TRC165 { + //Query whether the interface ‘interfaceID’ is supported + function supportsInterface(bytes4 interfaceID) external view returns (bool); + } +``` + +A wallet/broker/auction application MUST implement the `wallet` interface if it will accept safe transfers.Solidity + +```text +interface TRC721TokenReceiver { + //This method will be triggered when the ‘_to’ is the contract address during the ‘safeTransferFrom’ execution, and the return value must be checked, If the return value is not bytes4(keccak256("onTRC721Received(address,address,uint256,bytes)")) throws an exception. The smart contract which can receive NFT must implement the TRC721TokenReceiver interface. + function onTRC721Received(address _operator, address _from, uint256 _tokenId, bytes _data) external returns(bytes4); + } +``` + +> #### 🚧Note +> +> The hash of `bytes4(keccak256("onTRC721Received(address,address,uint256,bytes)))` is different from the Ethereum version `bytes4(keccak256("onERC721Received(address,address,uint256,bytes)))`. Please use `0x5175f878` instead of `0x150b7a02`. + +#### 1.1.2 OPTIONAL Metadata Extension Interface + +The metadata extension is OPTIONAL for TRC-721 smart contracts. This allows your smart contract to be interrogated for its name and for details about the assets which your NFTs represent.Solidity + +```text +interface TRC721Metadata { + //Return the token name + function name() external view returns (string _name); + + //Return the token symbol + function symbol() external view returns (string _symbol); + + //Returns the URI of the external file corresponding to ‘_tokenId’. External resource files need to include names, descriptions and pictures. + function tokenURI(uint256 _tokenId) external view returns (string); + } +``` + +URI is a URI link describing the \_tokenId asset, pointing to a JSON file that conforms to the TRC721 metadata description structure. When tokens are minted, each token needs to be assigned a unique URI:JSON + +```text +{ + "title": "Asset Metadata", + "type": "object", + "properties": { + "name": { + "type": "string", + "description": "Identifies the asset to which this NFT represents" + }, + "description": { + "type": "string", + "description": "Describes the asset to which this NFT represents" + }, + "image": { + "type": "string", + "description": "A URI pointing to a resource with mime type image/* representing the asset to which this NFT represents. Consider making any images at a width between 320 and 1080 pixels and aspect ratio between 1.91:1 and 4:5 inclusive." + } + } +} +``` + +#### 1.1.3 OPTIONAL Enumeration Extension Interface + +The enumeration extension is OPTIONAL for TRC-721 smart contracts. This allows your contract to publish its full list of NFTs and make them discoverable.Solidity + +```text +interface TRC721Enumerable { + //Return the total supply of NFT + function totalSupply() external view returns (uint256); + + //Return the corresponding ‘tokenId’ through ‘_index’ + function tokenByIndex(uint256 _index) external view returns (uint256); + + //Return the ‘tokenId’ corresponding to the index in the NFT list owned by the ‘_owner' + function tokenOfOwnerByIndex(address _owner, uint256 _index) external view returns (uint256); + } +``` + diff --git a/networks/tron-network/trx-and-trc-token/trc-721/trc-721-contract-interaction.md b/networks/tron-network/trx-and-trc-token/trc-721/trc-721-contract-interaction.md new file mode 100644 index 0000000..3760ad2 --- /dev/null +++ b/networks/tron-network/trx-and-trc-token/trc-721/trc-721-contract-interaction.md @@ -0,0 +1,124 @@ +# TRC-721 Contract Interaction + +## 1 Query the Token Name + +Call the function ‘name\(\)’ of TRC-721 to get the token name.Shell + +```text +curl -X POST https://api.shasta.trongrid.io/wallet/triggersmartcontract -d '{ + "contract_address":"418c921721ababd66313981e1ad49b19c4e799f24d", + "function_selector":"name()", + "owner_address":"411fafb1e96dfe4f609e2259bfaf8c77b60c535b93" + }' +``` + +Result:Shell + +```text +Result: +{"result":{"result":true},"constant_result":["0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000f596f757220546f6b656e204e616d650000000000000000000000000000000000"],"transaction":{"ret":[{}],"visible":false,"txID":"418a8fe76cb888e06c68cbe6a7c52b3b6f9c009877e16a2a87183868c5cbb1b0","raw_data":{"contract":[{"parameter":{"value":{"data":"06fdde03","owner_address":"411fafb1e96dfe4f609e2259bfaf8c77b60c535b93","contract_address":"418c921721ababd66313981e1ad49b19c4e799f24d"},"type_url":"type.googleapis.com/protocol.TriggerSmartContract"},"type":"TriggerSmartContract"}],"ref_block_bytes":"2d6d","ref_block_hash":"08e5816e980173a0","expiration":1615822557000,"fee_limit":400000000,"timestamp":1615822500321},"raw_data_hex":"0a022d6d220808e5816e980173a040c89e9eb4832f5a6d081f12690a31747970652e676f6f676c65617069732e636f6d2f70726f746f636f6c2e54726967676572536d617274436f6e747261637412340a15411fafb1e96dfe4f609e2259bfaf8c77b60c535b931215418c921721ababd66313981e1ad49b19c4e799f24d220406fdde0370e1e39ab4832f90018088debe01"}} +``` + +The name of the token is included in constant\_result, returned with the format of hex string. + +Since the return value is string type, string in the virtual machine is considered to be a variable-length type. Its data contains two parts: length and actual value. Therefore, the above return value needs to be parsed into three parts, which is split every 32 bytes. + +0000000000000000000000000000000000000000000000000000000000000020 pointer + +000000000000000000000000000000000000000000000000000000000000000F length + +596F757220546F6b656e204e616d650000000000000000000000000000000000 real value + +Parsed to semantics, the string data is read from the 32nd byte \(20 in hexadecimal represents 32 in decimal\), and the length is 15 bytes. The actual data is "596F757220546F6b656e204e616d65". convert it into a string form is "Your Token Name". + +## 2 Query the Token Symbol + +Shell + +```text +curl -X POST https://api.shasta.trongrid.io/wallet/triggersmartcontract -d '{ + "contract_address":"418c921721ababd66313981e1ad49b19c4e799f24d", + "function_selector":"symbol()", + "owner_address":"411fafb1e96dfe4f609e2259bfaf8c77b60c535b93" + }' +``` + +The symbol of the token is included in constant\_result\(YTN\), returned with the format of hex string. + +The parsing process is similar to the name\(\) method above, please refer to the detailed explanation of `name()`. + +## 3 Query the Balance + +Shell + +```text +curl -X POST https://api.shasta.trongrid.io/wallet/triggersmartcontract -d '{ + "contract_address":"419E62BE7F4F103C36507CB2A753418791B1CDC182", +"function_selector":"balanceOf(address)", +"parameter":"000000000000000000000041977C20977F412C2A1AA4EF3D49FEE5EC4C31CDFB", +"owner_address":"41977C20977F412C2A1AA4EF3D49FEE5EC4C31CDFB" + }' +``` + +**Parameters**: + +Contract\_address: contract address in hex string + +Owner\_address: the account address which triggers the contract function in hex string + +Function\_selector: the function to be called + +Parameters need to be passed to the contract methods. In this case, the address should be passed in. In this case, the address should be passed in. Since the address structure of TRON is the address prefix "41" + 20-byte address, 32 bytes are required when the address parameters are transmitted, so fill it with "0" in front. + +## 4 NFT Transfer + +Shell + +```text +curl -X POST https://api.shasta.trongrid.io/wallet/triggersmartcontract -d '{ +"contract_address":"419E62BE7F4F103C36507CB2A753418791B1CDC182", +"fee_limit": 400000000, +"function_selector":"transferFrom(address,address,uint256)", +"parameter":"0000000000000000000000001fafb1e96dfe4f609e2259bfaf8c77b60c535b9300000000000000000000000021ae4e504e68a75521221163faae1acd01deb3160000000000000000000000000000000000000000000000000000000000000001", +"call_value":0, +"owner_address":"419E62BE7F4F103C36507CB2A753418791B1CDC182" + }' +``` + +The parameter is to encode the address and uint256 in transfer\(address,uint256\), please refer to the [parameter encoding and decoding document](https://developers.tron.network/docs/parameter-and-return-value-encoding-and-decoding) for details. + +> #### 📘Note +> +> After calling this HTTP API, signing and broadcast APIs should also be called. + +Reference of transaction confirmation: [How to Confirm a Transaction](https://developers.tron.network/docs/transaction-11) + +## 5 Approve the Control of an NFT to Another Address + +Shell + +```text +curl -X POST https://api.shasta.trongrid.io/wallet/triggersmartcontract -d '{ +"contract_address":"419E62BE7F4F103C36507CB2A753418791B1CDC182", +"fee_limit": 400000000, +"function_selector":"approve(address,uint256)", +"parameter":"000000000000000000000000173ebb4f23dbdc69f31065d7f8d2dacab32e004f0000000000000000000000000000000000000000000000000000000000000001", +"call_value":0, +"owner_address":"419E62BE7F4F103C36507CB2A753418791B1CDC182" + }' +``` + +The parameter is to encode the address and uint256 in transfer\(address,uint256\), please refer to the parameter encoding and decoding document for details. + +> #### 📘Note +> +> After calling this HTTP API, signing and broadcast APIs should also be called. + +Reference of transaction confirmation: [How to Confirm a Transaction](https://developers.tron.network/docs/transaction-11) + +## 6 Query All NFT information of a TRC-721 Contract of a Specific Address + +* Call the function of balanceOf\(address \_owner\) to query the number of NFT holdings +* Call the function of tokenOfOwnerByIndex\(address \_owner, uint256 \_index\) to traverse all token\_ids +* Call the function of tokenURI\(uint256 \_tokenId\) to query the details of every NFT. + diff --git a/networks/tron-network/trx-and-trc-token/trc-721/trc-721-token-issuance.md b/networks/tron-network/trx-and-trc-token/trc-721/trc-721-token-issuance.md new file mode 100644 index 0000000..dbfb265 --- /dev/null +++ b/networks/tron-network/trx-and-trc-token/trc-721/trc-721-token-issuance.md @@ -0,0 +1,125 @@ +# TRC-721 Token Issuance + +## 1 Create a TRON Account + +Install the Chrome extension of [TronLink](https://www.tronlink.org/) to get ready for your issuance. You may create a new account in three ways: + +* create a new account +* restoring from a mnemonic phrase, private key or Keystore +* connect to a hardware wallet + +350 TRX is required in your account as the minimum. + +## 2 TRC-721 Code Modification + +You may modify the file of TRC721Token.sol to customise the name and symbol of the token. Remember to save your changes. + +TRC-721 contract template: [template](https://developers.tron.network/docs/contract-example-1)![](https://files.readme.io/91382cc-441615884766_.pic.jpg)![](https://files.readme.io/91382cc-441615884766_.pic.jpg) + +## 3 Deploy a TRC-721 Smart Contract + +Deploy with tronscan: [Contract Compiler](https://tronscan.io/#/contracts/contract-compiler) + +### 3.1 Connect to the Wallet + +![](https://files.readme.io/e0d7ad3-451615885008_.pic.jpg)![](https://files.readme.io/e0d7ad3-451615885008_.pic.jpg) + +### 3.2 Upload Contract Codes + +![](https://files.readme.io/97e3263-461615885065_.pic.jpg)![](https://files.readme.io/97e3263-461615885065_.pic.jpg)![](https://files.readme.io/62b74e8-471615885081_.pic.jpg)![](https://files.readme.io/62b74e8-471615885081_.pic.jpg) + +### 3.3 Compile the Contract + +![](https://files.readme.io/e61fca5-481615885109_.pic_hd.jpg)![](https://files.readme.io/e61fca5-481615885109_.pic_hd.jpg) + +Please choose the compiler version between 0.5.14 and 0.5.5![](https://files.readme.io/e8a29e1-491615885127_.pic.jpg)![](https://files.readme.io/e8a29e1-491615885127_.pic.jpg) + +Click ‘Confirm’ to compile. Compilation succeeds with this:![](https://files.readme.io/fe42cc9-501615885142_.pic.jpg)![](https://files.readme.io/fe42cc9-501615885142_.pic.jpg) + +### 3.4 Deploy the Contract + +![](https://files.readme.io/82b1060-511615885169_.pic_hd.jpg)![](https://files.readme.io/82b1060-511615885169_.pic_hd.jpg) + +Remember to choose TRC721Token, for it is the main contract.![](https://files.readme.io/502d573-521615885187_.pic_hd.jpg)![](https://files.readme.io/502d573-521615885187_.pic_hd.jpg) + +Click Confirm to deploy. There will be a pop-up from TronLink, click Accept to sign.![](https://files.readme.io/1451dd0-531615885206_.pic_hd.jpg)![](https://files.readme.io/1451dd0-531615885206_.pic_hd.jpg) + +## 4 Minting an NFT Token + +Log in to Tronscan with your wallet, and use the contract address to open the deployed TRC-721 contract. Here, take the TZ4NjvdqyCbWmZxXEEAb3bXhfT8f6YGxJd contract on the Nile test net as an example: + +* Choose 'Contract', 'Write Contract' + +![](https://files.readme.io/68befe3-731616989680_.pic_hd.jpg)![](https://files.readme.io/68befe3-731616989680_.pic_hd.jpg) + +* Find the mintWithTokenURI method, fill in the to\_address, tokenId, and the tokenURI corresponding to coral.json + +![](https://files.readme.io/91e5b67-741616989852_.pic.jpg)![](https://files.readme.io/91e5b67-741616989852_.pic.jpg) + +> #### 📘Metadata URI +> +> Refer to [Uploading NFT MEtadata to BTFS Network](https://developers.tron.network/docs/uploading-nft-metadata-to-the-btfs-network) for the generation of metadata URI. + +* Click 'send', then accept the signature. A 'true' will be displayed if the token was mint successfully + +![](https://files.readme.io/8f385c2-711616987914_.pic.jpg)![](https://files.readme.io/8f385c2-711616987914_.pic.jpg)![](https://files.readme.io/6007a35-751616990209_.pic.jpg)![](https://files.readme.io/6007a35-751616990209_.pic.jpg) + +## 5 Record TRC-721 Token + +Record with Tronscan: [Record tool](https://tronscan.org/#/tokens/create/Type) + +* Select token type + +![](https://files.readme.io/6c81294-1.png)![](https://files.readme.io/6c81294-1.png) + +Select the TRC721 token and click Yes. + +* Enter TRC721 token information Enter the basic information, contract address and social media information of the token. Fields with "\*" are required information. Please note that record must be logged in with the deployer address. + +![](https://files.readme.io/120ef5c-2.png)![](https://files.readme.io/120ef5c-2.png) + +Confirm all information required for the TRC721 token, click Submit.![](https://files.readme.io/cda6330-3.png)![](https://files.readme.io/cda6330-3.png) + +You will see a popup from Tronlink asking for your signature. Click Accept to sign the message.![](https://files.readme.io/612fbab-4.png)![](https://files.readme.io/612fbab-4.png) + +* Token successfully recorded + +![](https://files.readme.io/a12342d-5.png)![](https://files.readme.io/a12342d-5.png) + +## 6 Mobile Wallet adds TRC-721 tokens and transfer TRC-721 + +* Click the Add Assets button + +![](https://files.readme.io/d488fb3-1.png)![](https://files.readme.io/d488fb3-1.png) + +* Click the search button + +![](https://files.readme.io/b6ded3a-2.png)![](https://files.readme.io/b6ded3a-2.png) + +* Input TRC-721 contract address and click add button + +![](https://files.readme.io/2105f04-3.png)![](https://files.readme.io/2105f04-3.png) + +TRC721 added successfully![](https://files.readme.io/d7c0a14-4.png)![](https://files.readme.io/d7c0a14-4.png) + +* Click TRC-721 token, for example Wendy + +![](https://files.readme.io/d0dc74f-5.png)![](https://files.readme.io/d0dc74f-5.png) + +* Click Wendy 721 in List collectibles + +![](https://files.readme.io/3dbcbf4-6.png)![](https://files.readme.io/3dbcbf4-6.png) + +* Click send for transfer TRC-721 + +![](https://files.readme.io/8098de2-7.png)![](https://files.readme.io/8098de2-7.png) + +* Input address for receiving and enter your password for wallet + +![](https://files.readme.io/879ebd7-8.png)![](https://files.readme.io/879ebd7-8.png) + +* Transfer successfully + +![](https://files.readme.io/92f55bb-9.png)![](https://files.readme.io/92f55bb-9.png) + + diff --git a/networks/tron-network/trx-and-trc-token/trc-721/uploading-nft-metadata-to-btfs-network.md b/networks/tron-network/trx-and-trc-token/trc-721/uploading-nft-metadata-to-btfs-network.md new file mode 100644 index 0000000..b6bdbe2 --- /dev/null +++ b/networks/tron-network/trx-and-trc-token/trc-721/uploading-nft-metadata-to-btfs-network.md @@ -0,0 +1,114 @@ +# Uploading NFT Metadata to BTFS Network + +BitTorrent File System \(BTFS\) is a next-generation file-sharing protocol utilizing the TRON network and the BitTorrent ecosystem. + +Metadata is the detailed information of the NFT token. It is stored off the chain. Generally, the issuance of an NFT token will specify a URI path that points to the Metadata data of the token. + +### 1 Install BTFS + +Refer to [BTFS Installation Instructions](https://docs.btfs.io/docs/btfs-demo). + +### 2 Deposit BTT + +Uploading files to the BTFS network requires BTT as the payment method. + +The current storage price is 0.0037 BTT/Mb/month. For the uploader, redundant information will be added to the uploaded file and split into 30 copies. Any ten copies can be restored into a complete file so that each file will be uploaded three times the original file size. That is, for the uploader, the price is 3\*0.0037 BTT/Mb/month\(about $0.000038/Mb/month, calculated with the current price\). + +While using `btfs init` to initialize the local node, the command will generate a TRON wallet account associated with the node. You can check the TRON address corresponding to the wallet through `btfs id`. + +![](https://files.readme.io/bef9ccd-641616987616_.pic_hd.jpg) + +![](https://files.readme.io/bef9ccd-641616987616_.pic_hd.jpg) + +First, you need to recharge some BTT to the node's TRON account and then transfer the BTT of the TRON account to the accounting system of the BTFS network. + +#### Set a Password + +Run the following command to set a password for the node wallet:Shell + +```text +btfs wallet password ********** +``` + +#### Transfer BTT to BTFS network accounting system + +Running the following command will transfer the BTT of the local BTFS node account to the accounting system of the BTFS network. The minimum transfer amount is 10 BTT, and the BTT unit specified in the following command is μBTT \(1/1000000 of BTT\):Shell + +```text +btfs wallet deposit -p ********* 10000000 +``` + +### 3 Upload the File + +#### Step 1: Prepare a picture and name the picture coral.jpeg + +![](https://files.readme.io/e53617d-611616987482_.pic_hd.jpg) + +![](https://files.readme.io/e53617d-611616987482_.pic_hd.jpg) + +#### Step 2: Use Reed-Solomon encoding to add pictures to the local node + +Shell + +```text +btfs add --chunker=reed-solomon coral.jpeg +``` + +![](https://files.readme.io/a16e85b-621616987528_.pic_hd.jpg) + +![](https://files.readme.io/a16e85b-621616987528_.pic_hd.jpg) + +The `QmUK9nwtLEiHBJ48HAZHNmSQ53U6ADbRhATxs2tomadwKw` in the picture is the hash value of the file. + +#### Step 3: Upload files to the BTFS network through this hash value: + +Shell + +```text +btfs storage upload QmUK9nwtLEiHBJ48HAZHNmSQ53U6ADbRhATxs2tomadwKw +``` + +![](https://files.readme.io/f19d5b8-631616987592_.pic_hd.jpg) + +![](https://files.readme.io/f19d5b8-631616987592_.pic_hd.jpg) + +When you see "File storage successful" in the window of `btfs daemon`, it means the upload is successful + +![](https://files.readme.io/1a87623-641616987616_.pic_hd.jpg) + +![](https://files.readme.io/1a87623-641616987616_.pic_hd.jpg) + +#### Step 4: Verify that the picture can be downloaded + +Open the following link of the picture in the browser, you can see the picture indicating that the picture can be downloaded successfully: + +[https://gateway.btfs.io/btfs/QmUK9nwtLEiHBJ48HAZHNmSQ53U6ADbRhATxs2tomadwKw](https://gateway.btfs.io/btfs/QmUK9nwtLEiHBJ48HAZHNmSQ53U6ADbRhATxs2tomadwKw) + +![](https://files.readme.io/89b6fe0-651616987651_.pic_hd.jpg) + +![](https://files.readme.io/89b6fe0-651616987651_.pic_hd.jpg) + +### 4 Construct the NFT metadata file + +You can use the image link above to construct metadata for NFT. + +Create a JSON file according to the metadata example in the TRC-721 document and name it coral.json, and replace the description value in the image field with the BTFS download link of the image above, as shown in the figure: + +![](https://files.readme.io/fd99909-661616987692_.pic.jpg) + +![](https://files.readme.io/fd99909-661616987692_.pic.jpg) + +Run the btfs command to upload coral.json: + +![](https://files.readme.io/43483fc-671616987719_.pic_hd.jpg) + +![](https://files.readme.io/43483fc-671616987719_.pic_hd.jpg) + +Open the URI of the metadata file in the browser: +[https://gateway.btfs.io/btfs/QmWq4cp588QD8tzrSxvPs2bGikDdKyA35BT3iysBcP1jFD](https://gateway.btfs.io/btfs/QmWq4cp588QD8tzrSxvPs2bGikDdKyA35BT3iysBcP1jFD) + + +![](https://files.readme.io/6b62b0f-681616987739_.pic.jpg) + +![](https://files.readme.io/6b62b0f-681616987739_.pic.jpg) +