1
const main = async () =>{
    const abi = fs.readFileSync('erc20_abi.json', 'utf-8')
    const contract = new web3.eth.Contract(JSON.parse(abi), contractAddress);
    const transfer = contract.methods.transfer("0xDd63848C3A3582702B56c977480C12CCb14c6A0A", web3.utils.toHex(10e18));
    const encodedABI = transfer.encodeABI();

    const rawTransaction = {
        from: senderAddress,
        to: contractAddress,
        gas: 2000000,
        data: encodedABI
    };
    
    const privKey = Buffer.from(privateKey, 'hex');

    const customChainParams = { name: 'matic-mumbai', chainId: 80001, networkId: 80001 }
    const common = Common.default.forCustomChain('goerli',customChainParams)

    const tx = new Tx(rawTransaction, {common });
    tx.sign(privKey);
    const serializedTx = tx.serialize();

    const receipt = await web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'));
    console.log(receipt)
}

I am getting an error Method called with neither a hardfork set nor provided by param. Can someone please assist as to what I am doing wrong here.

1 Answer 1

1

You can use the custom() constructor & CustomChain enum provided by @ethereumjs/common

Install the package:

npm i @ethereumjs/common

Code Sample to use Polygon-Mumbai Network:

// require    
const { Common, CustomChain } = require("@ethereumjs/common");
const ethJs = require("ethereumjs-tx");

const common = Common.custom(CustomChain.PolygonMumbai);
// use the network in transaction
const tx = new ethJs.Transaction(rawTransaction, { common });

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.