I would like to send some ether to an account in ropsten testnet. I'm using the following code and the library https://docs.ethers.io/ethers.js/html/. However, instead of sending the ether to the to account, it is creating a contract. What am I doing wrong?

const wallet = new Wallet(config.privateKey);
wallet.provider = ethers.providers.getDefaultProvider('ropsten');

const transaction = {
    nonce: 0,
    gasLimit: config.gasLimit,
    gasPrice: gasPrice,
    to: to,
    value: ethers.utils.parseEther(amount),
    // data: "0x",
    // This ensures the transaction cannot be replayed on different networks
    chainId: 3 // ropsten

const signedTransaction = wallet.sign(transaction);

return new Promise((resolve, reject) => {
        .then(function(hash) {
            logTransaction(hash, config.sourceAddress, to, amount, gasPrice);
        }).catch(function(err) {

This is an example transaction created by running the code above:


EDIT: the problem comes from signing the transaction. If I do not sign the transaction, sendTransaction(transaction) works as expected and funds are transferred to to. If I sign the transaction and do sendTransaction(signedTransaction) it creates the mentioned contracts. What is the purpose of signing it, and why is it making the transaction to "fail"?

  • Print out the value of to? My guess is that it's null or 0.
    – user19510
    Feb 27, 2018 at 11:12
  • The value of to is: 0x00269e08097635F95aba776030e0907b56a7e181. Neither null nor 0. Maybe it needs some specific format or smthing like that? Feb 27, 2018 at 11:31
  • Ok, I've seen that the to field becomes undefined after signing the transaction. Is that normal, or what is the expected behaviour Feb 27, 2018 at 11:37
  • You mean the transaction object gets modified? Can you show code and output where you're doing console.log(transaction.to) above and below the sign call?
    – user19510
    Feb 27, 2018 at 12:05
  • I've found that the problem is signing the transaction. I'm editing the question Feb 27, 2018 at 12:06

1 Answer 1


The signedTransaction is serialized hex string of the transaction.

The Wallet.prototype.sendTransaction call is expecting a transaction object, not a serialized transaction. So, when it internally attempts to read tx.to, since tx is a string, it is getting null.

The Provider.prototype.sendTransaction call requires a signed transaction.

So, if you want to manually sign the transaction in your example, you could instead use:


Which is basically the same thing as if you had used:


The main difference is that Wallet.prototype.sendTransaction will automatically fill in some of the values for you, and will add some utility functions to the returned transaction object (such as wait())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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