# Transfer TRC20

## Python

ref: <https://tronpy.readthedocs.io/en/latest/>

ref: <https://tronpy.readthedocs.io/en/latest/contract.html#trigger-call>

```python
# DELETED
```

## Java

ref: <https://github.com/KI5FPL/tronj/blob/master/client/src/test/java/com/github/ki5fpl/tronj/client/ClientTest.java#L39>

## JavaScript (method 1)

```javascript
const TronWeb = require('tronweb');
const HttpProvider = TronWeb.providers.HttpProvider;
const fullNode = new HttpProvider("https://api.trongrid.io");
// const fullNode = new HttpProvider("http://192.168.1.162:8090");
const solidityNode = new HttpProvider("https://api.trongrid.io");
const eventServer = new HttpProvider("https://api.trongrid.io");
const privateKey = "3481E79956D4BD95F......C132F78A847906DE588C145";
const tronWeb = new TronWeb(fullNode, solidityNode, eventServer, privateKey);


const CONTRACT = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t";

const ACCOUNT = "TEQH6py1Pi8YHNgi9cPMHCKLboBTUZrsYT";

async function main() {
    const {
        abi
    } = await tronWeb.trx.getContract(CONTRACT);
    // console.log(JSON.stringify(abi));

    const contract = tronWeb.contract(abi.entrys, CONTRACT);

    const balance = await contract.methods.balanceOf(ACCOUNT).call();
    console.log("balance:", balance.toString());

    const resp = await contract.methods.transfer(ACCOUNT, 1000).send();
    console.log("transfer:", resp);
}

main().then(() => {
        console.log("ok");
    })
    .catch((err) => {
        console.log("error:", err);
    });

```

## JavaScript (method 2)

```javascript
const TronWeb = require('tronweb');
const HttpProvider = TronWeb.providers.HttpProvider;
const fullNode = new HttpProvider("https://api.trongrid.io");
// const fullNode = new HttpProvider("http://192.168.1.162:8090");
const solidityNode = new HttpProvider("https://api.trongrid.io");
const eventServer = new HttpProvider("https://api.trongrid.io");
const privateKey = "3481E79956D4BD95F3..........78A847906DE588C145";
const tronWeb = new TronWeb(fullNode, solidityNode, eventServer, privateKey);


const CONTRACT = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"; // USDT
const ACCOUNT = "TEQH6py1Pi8YHNgi9cPMHCKLboBTUZrsYT";

async function main() {
    let {
        transaction,
        result
    } = await tronWeb.transactionBuilder.triggerSmartContract(
        CONTRACT, 'transfer(address,uint256)', {
            feeLimit: 1_000_000,
            callValue: 0
        },
        [{
            type: 'address',
            value: ACCOUNT
        }, {
            type: 'uint256',
            value: 1000000
        }]
    );
    if (!result.result) {
        console.error("error:", result);
        return;
    }
    console.log("transaction =>", JSON.stringify(transaction, null, 2));

    const signature = await tronWeb.trx.sign(transaction.raw_data_hex);
    console.log("Signature:", signature);
    transaction["signature"] = [signature];

    const broadcast = await tronWeb.trx.sendRawTransaction(transaction);
    console.log("result:", broadcast);

    const {
        message
    } = broadcast;
    if (message) {
        console.log("Error:", Buffer.from(message, 'hex').toString());
    }
}

main().then(() => {
        console.log("ok");
    })
    .catch((err) => {
        console.trace(err);
    });
```

### Add Memo to TRC20 Transfer?

```
// use tronWeb.transactionBuilder.triggerSmartContract() with 
const unSignedTxnWithNote = await tronWeb.transactionBuilder.addUpdateData(unSignedTxn, memo, 'utf8');
const signedTxn = await tronWeb.trx.sign(unSignedTxnWithNote);
const ret = await tronWeb.trx.sendRawTransaction(signedTxn);

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://andelf.gitbook.io/tron/tron-by-example/transfer-trc20.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
