Ethers.js: How do I get testnet ether?

Created on 24 Apr 2018  ·  7Comments  ·  Source: ethers-io/ethers.js

I try send transaction by example from doc:

const privateKey = this.wallets[this.form.address].privateKey;
const wallet = new ethers.Wallet(privateKey);
wallet.provider = ethers.providers.getDefaultProvider({ name: 'ropsten', chainId: 3 });

const transaction = {
  to: 'walletAddress',
  value: ethers.utils.parseEther('0.1'),
  // gasLimit: 150000,
  gasPrice: ethers.utils.parseUnits('10.0', 'gwei'),
};

const estimateGasPromise = wallet.estimateGas(transaction);

estimateGasPromise.then((gasEstimate) => {
  console.log(gasEstimate.toString());
  transaction.gasLimit = gasEstimate;

  // Send the transaction
  const sendTransactionPromise = wallet.sendTransaction(transaction);

  sendTransactionPromise.then((transactionHash) => {
    console.log(transactionHash);
  });
});

but get the error

Error: insufficient funds for gas * price + value

I think it is because all wallets balance is 0, but in test network it must work

discussion

Most helpful comment

@fsanano , I created a youtube video on how to get ropsten ether, if you would like to see how it works. You can use "import existing account" instead of "create new account" for your case.

https://www.youtube.com/watch?v=sqlSQxFlmRM

All 7 comments

Is your ropsten account founded?

@dagogodboss dagogodboss I didn't now about ropsten account, https://ropsten.etherscan.io/ - here I am not found any form.
Or you mean something else ?

You must add testnet ether to your account.

Go to https://ropsten.ethers.io. Import your account and then click on the “testnet faucet” link, and click the button. ;)

@fsanano , you can fund your ropsten account using the ethers.io ropsten faucet: http://ropsten.ethers.io/#!/app-link/0xa5681b1fbda76e0d4ab646e13460a94fdcd3c1c1.ethers.space/

You will need to first add your ropsten account. There's import account option on the "Add Account" page. Then you can click on the "Send 3.141...ether" button. Once the transaction is confirmed, you will notice the balance is updated and you can also find your account on https://ropsten.etherscan.io/

Once your ropsten account has a balance, try your code again..

@fsanano , I created a youtube video on how to get ropsten ether, if you would like to see how it works. You can use "import existing account" instead of "create new account" for your case.

https://www.youtube.com/watch?v=sqlSQxFlmRM

@yuetloo, @ricmoo Thank you!!
Especially for the video))

Error gone, transaction passed!

Was this page helpful?
0 / 5 - 0 ratings