Subscribe to our free newsletter

To make sure you won't miss any valuable content we share with our community.

How to transfer USDT on Tron Network using Tronweb?

As we have mentioned earlier in our previous Previous article about Tron, this Blockchain, is one of the most popular networks among the blockchain users and developers. One of the main reasons is that it has low gas fees and at the same time high-speed and secure network. One of the main reasons that have made this blockchain so famous is the one-dollar gas fee. Of course, this is pretty much lower than that of the Ethereum network. Surely, one of the problems is that it is not very well documented the way the Ethereum development environment is. You cannot easily figure out an explicit way to send TRC-20 Usdt using the Tron network using python or JavaScript codes. In this article, we will show you how you can easily send TRC-20 Usdt on the TRON network by the means of Python and JavaScript codes.

The Importance of Transferring TRC-20 Usdt

There are many Blockchain developers in search of finding a way to transfer TRC-20 Usdt by the means of scripts. The main purpose is mainly to create a wallet or a payment gateway, exchange, Dex (Decentralized Exchange), and so on. There are 2 libraries that help developers materialize this idea. One of these libraries is written in Python and its name is tronpy. The other one is written in JavaScript and is named Tronweb.

The main reason why Sending TRC-20 Usdt is important is the same as asking why Blockchain is essential. The latter answer is because it makes the transactions much faster and decentralized and more independent from central authorities than any other institution in the world. The answer to the former question is just the same as the latter adding the fact that the gas fees on Tron Network are very low Not to mention that the blockchain is trusted worldwide. Moreover, most people count on its security. However, with the events that happened for Terra Network on May 2022, people are more suspicious about most of the blockchains’ network security.

Getting started with Tron Network development:

Like other networks, the Tron network has both mainnet and testnet. The testnet names for the Tron network are “nile” and “shasta”. You can get a number of test TRC-20 Usdt or any other test TRC-20 token including Tron by signing in to your discord account and asking the faucet to give you some of it. We will get that later after we create an account using on Tron network and get our account address and the private key. Before writing any you need to first install the tronpy module: pip install tronpy

# On Linux use pip3

pip3 install tronpy
Now we are ready to write our very first script.

1. Creating a Test Account:

Create a new python file and call it TronAccount.py. Then enter the following Script into it:


from tronpy import Tron, Contract
from tronpy.keys import PrivateKey

client = Tron(network="shasta")
wallet = client.generate_address()
print("Wallet address:  %s" % wallet['base58check_address'])
print("Private Key:  %s" % wallet['private_key'])


The above script will simply connect to the shasta testnet and create a wallet. By using the wallet, it derives the account address and the private key. Now we should run the script: python3 TronAccount.py This results in: Wallet address: TS2AThtoLPTR2bRakWc9nitkKDwDvkPJ6H
Private Key: 464068d2a6bac31aa1eb4db1764647799fad45e80661f311f379a38061397d28
Now that we have our own account and the private key, we can get some test shasta TRC-20 Usdt from the Tron Discord page. To do this, you need to ask for it in the faucets section by commenting: !shasta_usdt "Your_Account_Address" Notice that you will need to place the account address that you have got in the account address section in the above comment. The below photo will guide you toward this step:

Also, if you want some test Tron tokens from shasta testnet, you can use the below comment in the faucet section of the Tron Discord: !shasta "Your_Account_Address" Notice that the transfer of the test tokens from the faucet may not be immediately performed and you might need to wait for even hours to get it. Especially if you have asked for the test tokens twice. To make sure you have got the tokens, you will need to check your balance.

2. Checking the balance of the account for TRC-20 Usdt:

to check the balance of the account you can simply use the following script. Notice that if you haven’t had any transactions on the account, or haven’t received any token from any other account, your account is not activated, yet. After getting activated. When your account is not activated you will face the Error saying that the account is not found on-chain.


from tronpy import Tron

client = Tron(network="shasta")
balance = client.get_account_balance(str('TS2AThtoLPTR2bRakWc9nitkKDwDvkPJ6H'))
print (balance)


In the above code we have once more connected to the shasta testnet and this time we have checked the balance of the account. After making sure you have got some test usdt, it is time to create another account to transfer our test TRC-20 Usdt tokens into it. To do so, you can use the first piece of code we wrote for creating our first account. Keep the account addresses and the private key for the next step which is transferring the tokens from one account to the other.

3. Transferring TRC-20 Usdt Test tokens:

After all, we have got to the exciting part of this tutorial. We are going to transfer TRC-20 Usdt from one account to the other. To write the code, we need to install the Tronweb JavaScript module first. The following two commands using npm and yarn will both help install the package: npm install tronweb
# Using yarn
yarn add tronweb
Now, create a JavaScript file called transfer.js and also a package.json to contain the “type”: “module”, part.

"type": "module"


The general form of transfer.js should be like the following script. Notice that you should enter your specifications in it.

import TronWeb from 'tronweb';

const tronWeb = new TronWeb({
    fullHost: "trongrid address according to the preferred testnet or mainnet",
    headers: { "TRON-PRO-API-KEY": AppKey },
    privateKey: "The Sender's Private Key",
});

const options = {
    feeLimit: 10000000,
    callValue: 0
};

const tx = await tronWeb.transactionBuilder.triggerSmartContract(
    "TRC-20 Contract Address according to network you use", 'transfer(address,uint256)', options,
    [{
      type: 'address',
      value: "Account Address of the Receiver"
    }, {
      type: 'uint256',
      value: (Amount) * 1000000
    }],
    tronWeb.address.toHex("Account Address of the sender")
);

const signedTx = await tronWeb.trx.sign(tx.transaction);
const broadcastTx = await tronWeb.trx.sendRawTransaction(signedTx);

console.log(signedTx);
console.log(broadcastTx);


For our case, the code becomes just the same as below.

import TronWeb from 'tronweb';

const tronWeb = new TronWeb({
    fullHost: "https://api.shasta.trongrid.io",
    //headers: { "TRON-PRO-API-KEY": AppKey },
    privateKey: "464068d2a6bac31aa1eb4db1764647799fad45e80661f311f379a38061397d28",
});

const options = {
    feeLimit: 10000000,
    callValue: 0
};

const tx = await tronWeb.transactionBuilder.triggerSmartContract(
    "TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs", 'transfer(address,uint256)', options,
    [{
      type: 'address',
      value: "TS1KhsETNqnmGgJMsWUGGzsbRpWRYkcAdD"
    }, {
      type: 'uint256',
      value: 5 * 1000000
    }],
    tronWeb.address.toHex("TS2AThtoLPTR2bRakWc9nitkKDwDvkPJ6H")
);

const signedTx = await tronWeb.trx.sign(tx.transaction);
const broadcastTx = await tronWeb.trx.sendRawTransaction(signedTx);

console.log(signedTx);
console.log(broadcastTx);


We have replaced the shasta full host address and commented the API key as we do not need it for the testnet. We have also entered the private key of the sender and the public keys of the receiver and the sender. The other thing we have specified is the amount that we want to transfer. And most important, we have placed the TRC-20 usdt shasta testnet contract address. Note that for the usdt the contract address differs based on which network it is on. Generally, you can use the following three contract addresses based on your preferred network:

Shasta Testnet: TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs
Nile Testnet: TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf
Mainnet: TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t


And for the testnet addresses, you can use the followings.

Shasta Testnet:  https://api.shasta.trongrid.io
Nile Testnet: https://api.nileex.io/


Now it is time to finally run our code and see the result of the transaction. If the sender’s account is not activated, there will be no transferring but at least will see the result of a successful transaction. to run the JavaScript code, you can simply run the following. node transfer.js As a result you will see. {
  visible: false,
  txID: 'd50f206ed3609a6e766a969d4c97c4f3b3d1b423e15422f18bc4dfd5c20ffd5b',
  raw_data: {
   contract: [ [Object] ],
   ref_block_bytes: 'ae30',
   ref_block_hash: '9c128228851ac4a2',
   expiration: 1662581406000,
   fee_limit: 10000000,
   timestamp: 1662581347555
  },
  raw_data_hex:'0a0...long number...',
  signature: [
  'c7fb...long number...'
  ]
}
{
  code: 'CONTRACT_VALIDATE_ERROR',
  txid: 'd50f206ed3609a6e766a969d4c97c4f3b3d1b423e15422f18bc4dfd5c20ffd5b',
  message: '436f...long number...'
}
The above is the result of printing the result of a signed and broadcasted transaction.

Conclusion

In this tutorial-based article, you learned how to create an account on the Tron Shasta testnet to get some test TRC20 Usdt from the shasta testnet faucet. Also, you learned how to check the balance of an account, and in the end, you learned how to transfer the test Usdt tokens on the shasta testnet. In the next article, you will learn about more Tron Blockchain interactions and useful projects that can help you create your cool projects.

Download this Article in PDF format

3d websites

Arashtad Custom Services

In Arashtad, we have gathered a professional team of developers who are working in fields such as 3D websites, 3D games, metaverses, and other types of WebGL and 3D applications as well as blockchain development.

Arashtad Serivces
Drop us a message and tell us about your ideas.
Fill in the Form
Blockchain Development

Introduction to Tron Network and Its Features

The TRON (TRX) network is committed to advancing the decentralization of the internet by using blockchain technology and DApps. Since the launch of its mainnet in May 2018, this network, founded in September 2017 by Justin Sun, has maintained its outstanding performance. With over 100 million monthly active users, BitTorrent, a pioneer in decentralized services, was acquired and integrated into TRON in July 2018. This blockchain is also the largest circulating supply of stablecoins in the world, surpassing Tether (USDT) on Ethereum in April 2021. This network became a DAO (Decentralized Automated Organization) in December 2021 after decentralizing fully.

What are the TRON Network Tokens?

As part of its Protocol, the TRON Foundation released TRONIX, a mainnet token. TRX tokens act as the primary unit of accounts on the TRON blockchain. And the value of all other cryptocurrencies is derived from TRX tokens. BitTorrent (BTT), JUST (JST), USD Coin (USDC), Tether (USDT), and NFTs are other tokens. As a medium of exchange for all TRC-based tokens, TRX unites the entire TRON ecosystem with a variety of application scenarios.

How Does TRON Network Work?

TVM (TRON Virtual Machine) is a compact virtual machine that is an important part of this ecosystem. Its main purpose is to deliver a robust blockchain system that is stable, practical, safe, and scalable. By using the TRC-20 standard, TVM-compatible tokens can be created by the means of smart contracts. These tokens are completely ERC-20 compliant. The TRON architecture consists of TVM, core, storage, and the application layer. In the core layer, we have the smart contracts, consensus mechanism – which is the delegated proof of stake (DPoS) for this ecosystem – and account management.

How Does DPoS (Delegated Proof of Stake) Work?

Delegated proof-of-stake is a blockchain consensus technique that allows users to cast votes for different delegates. once elected, these delegates have the power to decide important network-wide issues. In TRON’s ecosystem, 27 super representatives (SRs) maintain transaction history and verify transactions. The mechanism picks a super representative every six hours, and they receive a TRX coin for their services. A new block is added to the TRON blockchain every three seconds, and those who add blocks receive 32 TRX coins.

TRON uses a virtual machine and an efficient instruction set. Its smart contracts use Solidity and other advanced languages. TRON’s unique distributed storage protocol consists of Block Storage and State Storage. The possibilities for utility applications are endless since TRON makes it possible to deploy and execute smart contracts. Developers can create a wide variety of DApps and wallets.

What makes Tron Unique?

There are three types of nodes on the TRON network: the Witness Node, the Full Node, and the Solidity Node. SRs create witness nodes. These nodes are primarily responsible for creating proposals and voting on them. Full Nodes broadcast application programming interfaces (APIs), transactions, and blocks. Solidity Nodes, which also offer indexable APIs, sync blocks from other Full Nodes. The TRON network offers three different types of accounts: regular accounts, token accounts, and contract accounts.

What are the Advantages of TRON?

The platform has the ability to allow users to participate in the selection of super representatives by holding and staking TRX. additionally, the platform enables content creators to earn payments while maintaining complete control. In this way, TRON’s cryptocurrency ecosystem enables you to share content with others while also receiving payment for the information and content you produce as a content creator. TRON’s decentralized digital platform also charges a transaction fee of just $0.000005.

Moreover, TRON’s network has the advantage of allowing 2000 transactions per second, unlike Bitcoin (BTC), which supports three to six transactions, and Ethereum (ETH), which permits 25 transactions. Trading TRX coins is possible between global buyers and sellers around the globe.

TRON vs. Ethereum

A number of basic building blocks, such as smart contracts, decentralized applications (dApps), and tokens, are used in the Tron network structure. Similar to Ethereum. In fact, it has been criticized for perhaps “going too far” by borrowing rather than building the basics of its platform. USD Coin, a cryptocurrency tied to the US Dollar, is circulating on Tron less than a month after support was launched for it. Tronix and Ethereum are becoming competitors for the business of cryptocurrency traders.

Coindesk reported in July 2021 that this could be another sign that crypto traders are turning more and more to blockchains that offer cheaper transaction fees and faster speed than Ethereum. TRX ranked 31st in market capitalization according to CoinRanking.com on Aug. 5, 2021. its price was $0.0705, giving it a market capitalization of $4.66 billion. Its all-time high on that date was $0.2180.

Financial Institutions that use TRON:

Refereum

With this platform, gamers can earn TRX while streaming, and viewers can earn rewards while watching. Tron’s media focus as well as the huge potential for blockchain and gaming integration make the partnership a good fit. Streaming service DLive is the main focus of their efforts, which Tron accessed through BitTorrent’s partnership with it.

Metal Pay

In partnership with Metal Pay, users can now easily purchase TRX tokens for cash through either Metal Pay’s website or app. Metal Pay is an online payment service for sending money worldwide. As a result, adoption is broken down, which is the process of acquiring TRX, which some people may have found difficult before.

Samsung

Samsung has added Tron to its Blockchain Keystore. It is a milestone achievement for blockchain technology. Because new content creators receive a reasonable amount of compensation for their efforts. In addition to that, their dApps now exist as one of the largest app markets in the world. As of today, Samsung users with the latest versions of their phones will be able to access Tron dApps through the Samsung app store.

Conclusion

In this article, you learned about the TRON network, its architecture, its advantages, and so on. TRON ecosystem had a clear purpose in mind: to give content creators more recognition for their work. Currently, the media industry is structured in an unfair way. A few big companies like YouTube, Facebook, and Apple control a large proportion of views and uploads. They not only control what can be seen, but they also receive the vast majority of revenue generated by media. creators will only receive a small proportion of it. the platform’s goal is to correct this.

Download this Article in PDF format

3d websites

Arashtad Custom Services

In Arashtad, we have gathered a professional team of developers who are working in fields such as 3D websites, 3D games, metaverses, and other types of WebGL and 3D applications as well as blockchain development.

Arashtad Serivces
Drop us a message and tell us about your ideas.
Fill in the Form
Blockchain Development