Giter Site home page Giter Site logo

Comments (2)

StarLXL avatar StarLXL commented on July 23, 2024

senToken function is used to create an unsigned TRC10 token transfer transaction.
If you want to create a TRC20 transfer transaction, use the triggersmartcontract function.
Please refer to this link for how to use it.
https://developers.tron.network/reference#triggersmartcontract

from tronweb.

EvanXzj avatar EvanXzj commented on July 23, 2024

@StarLXL Thank you for your reply!
I have write a demo like blew:

const privateKey = '5bcf9b39c69bf374c0441f06cfcd7b28a5ea6c6018c5eeace591f4db75e4dd01';
const tronWeb = new TronWeb({
    fullHost: 'https://api.shasta.trongrid.io',
});

const anthoerTronAddress = 'TX1mBCZSdXzggYcV16yEZ39L9wpF8eEmgo';
const isuuerAddres = 'TMPgjknWZsYJSmPjpY5V33qmKoruUqcYA3';
const contractAddress = 'TLdPQwEeTAaCfNrGRBhmxnScDmfZL2Perz';


async function main() {
    try {
        const parameter = [{ type: 'address', value: anthoerTronAddress }, { type: 'uint256', value: '10000000000000000' }];
        const options = {
            feeLimit: 100000000,
            callValue: 0,
        };

        const transaction = await tronWeb.transactionBuilder.triggerSmartContract(tronWeb.address.toHex(contractAddress), 'transfer(address,uint256)', options, parameter, tronWeb.address.toHex(isuuerAddres));
        if (!transaction.result || !transaction.result.result) {
            throw new Error('transaction crated failed');
        }

        const signedTransaction = await TronWeb.utils.crypto.signTransaction(privateKey, transaction.transaction);

        const broadcast = await tronWeb.trx.sendRawTransaction(signedTransaction);
    } catch (error) {
        console.log('Error', error);
    }
}

main();

It is ok if transfer a trc20 token from contract isuuerAddres to another anthoerTronAddress.
What if I want to transfer trc20 token between two non-issuer accounts, what triggerSmartContract function params should like?

I have tried change triggerSmartContract issuerAddress param to anthoerTronAddress.
when i Broadcast, i got an error:

[ { "apiRet": { "code": "SIGERROR", "message": "validate signature error b483c6900340d6ee838b08a54cb9a605cab087bfe5a0ca5b9d0c7da24a8f1f750af727100138bc7105202b86ee9e8b918af93172f7e479ab2620c71d63ec486100 is signed by TYEQ1Xc3ejLHnEPWa9YpH1jMWSHoNhW5t7 but it is not contained of permission.", "txid": "e747645a2716d9fb45210cab9255ff43928ccfac8dbbd024b20c72e80805665c" }, "broadcastTime": 1589513194, "id": 2 } ]

Is this function can only call by contract issuer?

from tronweb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.