PatrickAlphaC / ethers-simple-storage-fcc

90 stars 128 forks source link

"TypeError: transaction chainId mismatch" error while deploying raw transaction to local Ganache blockchain #98

Open Ilaay opened 1 year ago

Ilaay commented 1 year ago

Hi! I am getting "TypeError: transaction chainId mismatch" error while deploying raw transaction to local Ganache. I tried changing chainId to 31377 and 5777 and changing local Ganache blockchain NETWORK ID to 31377 and 5777. Still getting same error. I'd appreciate your help.

My deploy.js code:

const ethers = require("ethers");
const fs = require("fs-extra");

async function main() {
  const provider = new ethers.JsonRpcProvider(
    "http://127.0.0.1:7545" //double checked
  );

  const wallet = new ethers.Wallet(
    "0xd06079ff3aecb1aef0902d7dfca07e01c60d500ae50a2e5e94eeaf5e86b09c15", //private key (only for testing), double checked
    provider
  );

  const abi = fs.readFileSync("./SimpleStorage_sol_SimpleStorage.abi", "utf-8");
  const binary = fs.readFileSync(
    "./SimpleStorage_sol_SimpleStorage.bin",
    "utf-8"
  );

  // const contractFactory = new ethers.ContractFactory(abi, binary, wallet);
  // console.log("deploying...");
  // const contract = await contractFactory.deploy(); //deployed contract

  const nonce = await wallet.getNonce();

  const tx = {
    nonce: nonce,
    gasPrice: 20000000000,
    gasLimit: 10000000,
    to: null, //signing contract
    value: 0, //no funds
    data: "0x608060405234801561001057600080fd5b50610ad4806100206000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c806309ce9ccb1461006757806320f174841461008557806336de1d62146100b5578063a009491b146100d1578063b6339418146100ef578063d0f3e09c1461010b575b600080fd5b61006f61013c565b60405161007c9190610406565b60405180910390f35b61009f600480360381019061009a919061057b565b610142565b6040516100ac9190610643565b60405180910390f35b6100cf60048036038101906100ca9190610665565b6101f8565b005b6100d9610296565b6040516100e69190610406565b60405180910390f35b61010960048036038101906101049190610709565b61029f565b005b61012560048036038101906101209190610709565b6102a9565b604051610133929190610736565b60405180910390f35b60005481565b60028180516020810182018051848252602083016020850120818352809550505050505060009150905080546101779061079c565b80601f01602080910402602001604051908101604052809291908181526020018280546101a39061079c565b80156101f05780601f106101c5576101008083540402835291602001916101f0565b820191906000526020600020905b8154815290600101906020018083116101d357829003601f168201915b505050505081565b60016040518060400160405280848152602001838152509080600181540180825580915050600190039060005260206000209060020201600090919091909150600082015181600001908161024d9190610979565b5060208201518160010190816102639190610979565b505050806002836040516102779190610a87565b908152602001604051809103902090816102919190610979565b505050565b60008054905090565b8060008190555050565b600181815481106102b957600080fd5b90600052602060002090600202016000915090508060000180546102dc9061079c565b80601f01602080910402602001604051908101604052809291908181526020018280546103089061079c565b80156103555780601f1061032a57610100808354040283529160200191610355565b820191906000526020600020905b81548152906001019060200180831161033857829003601f168201915b50505050509080600101805461036a9061079c565b80601f01602080910402602001604051908101604052809291908181526020018280546103969061079c565b80156103e35780601f106103b8576101008083540402835291602001916103e3565b820191906000526020600020905b8154815290600101906020018083116103c657829003601f168201915b5050505050905082565b6000819050919050565b610400816103ed565b82525050565b600060208201905061041b60008301846103f7565b92915050565b6000604051905090565b600080fd5b600080fd5b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6104888261043f565b810181811067ffffffffffffffff821117156104a7576104a6610450565b5b80604052505050565b60006104ba610421565b90506104c6828261047f565b919050565b600067ffffffffffffffff8211156104e6576104e5610450565b5b6104ef8261043f565b9050602081019050919050565b82818337600083830152505050565b600061051e610519846104cb565b6104b0565b90508281526020810184848401111561053a5761053961043a565b5b6105458482856104fc565b509392505050565b600082601f83011261056257610561610435565b5b813561057284826020860161050b565b91505092915050565b6000602082840312156105915761059061042b565b5b600082013567ffffffffffffffff8111156105af576105ae610430565b5b6105bb8482850161054d565b91505092915050565b600081519050919050565b600082825260208201905092915050565b60005b838110156105fe5780820151818401526020810190506105e3565b60008484015250505050565b6000610615826105c4565b61061f81856105cf565b935061062f8185602086016105e0565b6106388161043f565b840191505092915050565b6000602082019050818103600083015261065d818461060a565b905092915050565b6000806040838503121561067c5761067b61042b565b5b600083013567ffffffffffffffff81111561069a57610699610430565b5b6106a68582860161054d565b925050602083013567ffffffffffffffff8111156106c7576106c6610430565b5b6106d38582860161054d565b9150509250929050565b6106e6816103ed565b81146106f157600080fd5b50565b600081359050610703816106dd565b92915050565b60006020828403121561071f5761071e61042b565b5b600061072d848285016106f4565b91505092915050565b60006040820190508181036000830152610750818561060a565b90508181036020830152610764818461060a565b90509392505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b600060028204905060018216806107b457607f821691505b6020821081036107c7576107c661076d565b5b50919050565b60008190508160005260206000209050919050565b60006020601f8301049050919050565b600082821b905092915050565b60006008830261082f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff826107f2565b61083986836107f2565b95508019841693508086168417925050509392505050565b6000819050919050565b600061087661087161086c846103ed565b610851565b6103ed565b9050919050565b6000819050919050565b6108908361085b565b6108a461089c8261087d565b8484546107ff565b825550505050565b600090565b6108b96108ac565b6108c4818484610887565b505050565b5b818110156108e8576108dd6000826108b1565b6001810190506108ca565b5050565b601f82111561092d576108fe816107cd565b610907846107e2565b81016020851015610916578190505b61092a610922856107e2565b8301826108c9565b50505b505050565b600082821c905092915050565b600061095060001984600802610932565b1980831691505092915050565b6000610969838361093f565b9150826002028217905092915050565b610982826105c4565b67ffffffffffffffff81111561099b5761099a610450565b5b6109a5825461079c565b6109b08282856108ec565b600060209050601f8311600181146109e357600084156109d1578287015190505b6109db858261095d565b865550610a43565b601f1984166109f1866107cd565b60005b82811015610a19578489015182556001820191506020850194506020810190506109f4565b86831015610a365784890151610a32601f89168261093f565b8355505b6001600288020188555050505b505050505050565b600081905092915050565b6000610a61826105c4565b610a6b8185610a4b565b9350610a7b8185602086016105e0565b80840191505092915050565b6000610a938284610a56565b91508190509291505056fea2646970667358221220efae7dd756f973105a1a4559c0d522ce4f4547aa2681ab28dd6823aae133a30764736f6c63430008130033",
    chainId: 1377, //Ganache NETWORK ID which causes problems
  }

  const sentTransactionResponse = wallet.sendTransaction(tx);
  (await sentTransactionResponse).wait(1);
  console.log(sentTransactionResponse);
}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);   
    process.exit(1);
  });

Error code:

TypeError: transaction chainId mismatch (argument="tx.chainId", value=1377, code=INVALID_ARGUMENT, version=6.7.1) 
    at makeError (D:\WEB3\node_modules\ethers\lib.commonjs\utils\errors.js:118:21)
    at assert (D:\WEB3\node_modules\ethers\lib.commonjs\utils\errors.js:142:15)
    at assertArgument (D:\WEB3\node_modules\ethers\lib.commonjs\utils\errors.js:154:5)
    at Wallet.populateTransaction (D:\WEB3\node_modules\ethers\lib.commonjs\providers\abstract-signer.js:78:43)   
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Wallet.sendTransaction (D:\WEB3\node_modules\ethers\lib.commonjs\providers\abstract-signer.js:182:21)
    at async main (D:\WEB3\deploy.js:38:4) {
  code: 'INVALID_ARGUMENT',
  argument: 'tx.chainId',
  value: 1377
}

image

RaafayAsif commented 1 year ago

Set network id back to 5777 in ganache and in JS file set chainId to 1337 by default its 1337