0

I want to transfer a Bep20 custom token from a wallet to another using web3.js in Binance Smart Chain. I can transfer BNB using this code:

// Create transaction
const myTransfer = async () => {
    console.log(
        `Attempting to make transaction from ${addressFrom} to ${addressTo}`
    );

    const createTransaction = await web3.eth.accounts.signTransaction(
        {
            from: addressFrom,
            to: addressTo,
            value: 'value',
            gas: '30000',
        },
        privateKey
    );

    // Deploy transaction
    const createReceipt = await web3.eth.sendSignedTransaction(
        createTransaction.rawTransaction
    );
    console.log(
        `Transaction successful with hash: ${createReceipt.transactionHash}`
    );
};

How can I send a token from the same wallet?

2
  • It doesn't work. I'm using Binance Smart Chain Testnet and I after some days I found a solution using ethereumjs-common to modify my ethereumjs-tx Transaction object. I got some aditional problems and I'm not sure if is the solution because it dont admits Chapel network. You can see chains here: chainid.network/chains
    – gopeca
    Apr 28 at 10:33
  • It seems ethereumjs-txt has changed since the question was answered. I'd suggest either to modify this question or create a new one with the specific problem with ethereumjs-common.
    – Ismael
    Apr 28 at 14:00

Browse other questions tagged or ask your own question.