How to solve Returned error: only replay-protected (EIP-155) transactions allowed over RPC?

var Tx = require('@ethereumjs/tx').Transaction;
var privateKey = Buffer.from('affasdfsdf', 'hex');
var Web3 = require('web3');

const web3 = new Web3('https://speedy-nodes-nyc.moralis.io/**********/bsc/mainnet');
var rawTx = {
    nonce: '0x00',
    gasPrice: '0x09184e72a000',
    gasLimit: '0x2710',
    to: '0x0000000000000000000000000000000000000000',
    value: '0x00',
    data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057',
}

var tx = new Tx(rawTx);
tx.sign(privateKey);

var serializedTx = tx.serialize();

web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
    .on('receipt', console.log);

usually you also have to specify a chain id in that rawTx data

I tried but does not work

this would work fine, it looks like you have a combination of etherjs and web3 there

x = async () => { 
var privateKey = '0x148ce564d427a3311b6536bbcff9380d69395b06ed6c486954e971d960fe8708'
var Web3 = require('web3');

const web3 = new Web3('https://speedy-nodes-nyc.moralis.io/asfasdfa/bsc/mainnet');
var rawTx = {
    nonce: 1,
    gasPrice: '0x09184e72a000',
    gasLimit: '0x20000',
    to: '0x0000000000000000000000000000000000000000',
    value: '0x00',
    data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057',
}

tx = await web3.eth.accounts.signTransaction(rawTx,privateKey);
console.log(tx)

}
x()

Hello,

Probably youโ€™ve solved your issue, but, the problem was with the below statements:

var tx = new Tx(rawTx);
tx.sign(privateKey);

Should be changed to:

var tx = new Tx(rawTx);
tx = tx.sign(privateKey);

.sign() returns a new tx object and you have to โ€œreassignโ€ the value

In case someone else has the same problem !