ethers.js: Error: invalid transaction object when attempting to deploy contract

here is my code:

var bytecode = contractjson.bytecode
var transaction = ethers.Contract.getDeployTransaction(bytecode, abi);
var signedTx = wallet.sign(transaction)
var deployTx = await wallet.sendTransaction(signedTx)
let tx = await provider.waitForTransaction(deployTx)

this causes the following unhandled promise rejection error:

Error: invalid transaction object
    at Wallet.sendTransaction

not sure what’s going wrong here - perhaps the bytecode isn’t formatted correctly? any help is much appeciated 😃

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

I’m initializing the wallet with an encrypted JSON keystore: var wallet = await Wallet.fromEncryptedWallet(walletJson, password) walletJson is an imported UTC file generated with geth

here’s the entire error message:

{ Error: invalid sender
    at getResult (/home/elizabeth/shyft_jsbridge/node_modules/ethers/providers/json-rpc-provider.js:34:21)
    at exports.XMLHttpRequest.request.onreadystatechange (/home/elizabeth/shyft_jsbridge/node_modules/ethers/providers/provider.js:621:30)
    at exports.XMLHttpRequest.dispatchEvent (/home/elizabeth/shyft_jsbridge/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:591:25)
    at setState (/home/elizabeth/shyft_jsbridge/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:610:14)
    at IncomingMessage.<anonymous> (/home/elizabeth/shyft_jsbridge/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:447:13)
    at IncomingMessage.emit (events.js:185:15)
    at endReadableNT (_stream_readable.js:1106:12)
    at process._tickCallback (internal/process/next_tick.js:114:19)

it seems to be the wallet.sendTransaction line that generates the error; all the code before that works ok.

also, I’m able to send transactions to interact with a contract, so I think the wallet is set up ok. only deployment isn’t working

let provider = new providers.JsonRpcProvider(“http://localhost:8545”, “unspecified”)

This resolved my issue! Thanks!