1

How do I sign and send a transaction using web3.js and ethereumjs-tx on the BSC testnet?

I have found this question and answer:

Is it possible to send transaction in Binance Smart Chain using web3 and ethereumjs-tx?

This only seems to cover the mainnet:

const common = Common.default.forCustomChain('mainnet', {
  name: 'bnb',
  networkId: 56,
  chainId: 56
}, 'petersburg');

If I substitute the chainId for 97 (BSC Testnet Id) and replace 'petersburg' with Chapel. I get 'Error: Chain with name Chapel not supported'

Any help is greatly appreciated. Thanks in advance.

2
  • Not the answer, but Petersburg is the name of hardfork (update) and not the chain
    – Majd TL
    May 15, 2021 at 20:54
  • Thank you. I hadn't noticed that. I assume the fork would be the same for the BSC Testnet then? I'll try swapping over just the networkId and chainId to 97.
    – ImJhardy
    May 15, 2021 at 21:07

2 Answers 2

1

I gave up trying to ethereumjs-tx in the end as I came across this:

https://stackoverflow.com/questions/64526925/how-to-swap-tokens-on-uniswap-using-web3-js

Managed to get that solution up and running it solved that particular error I was getting.

0

First argument can only have 5 possible values, mainnet, ropsten, rinkeby, goerli and kovan. You can confirm here.

But you can work around that by overriding parameters with second argument. So in your case...

var common = Common.forCustomChain(
    'ropsten',
    {
        name: 'Binance Smart Chain Testnet',
        networkId: 97,
        chainId: 97,
        url: 'https://data-seed-prebsc-1-s1.binance.org:8545'
    },
    'istanbul',
);

should work. 97 is BSC testnet network and chain id.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.