:/ Following Learn step by step not clear for noob

Hello

I follow the step by step tutorial. (truffle)
I'm at the end of this step https://docs.openzeppelin.com/learn/connecting-to-public-test-networks#creating-a-new-account

(await ethers.provider.getBalance(accounts[0])).toString()

return

truffle(rinkeby)> (await ethers.provider.getBalance(accounts[0])).toString()
Uncaught ReferenceError: ethers is not defined
    at evalmachine.<anonymous>

I don't understand what to understand :upside_down_face:
it seems to me that rinkeby does not offer the use of the ethers library by magic :slight_smile:

Best Regards.

1 Like

I'm trying this from a new script:

const accounts = await web3.eth.getAccounts();
console.log(accounts);

const ethers = require('ethers');
const provider =  ethers.getDefaultProvider();
const balance = (await provider.getBalance(accounts[0])).toString();
console.log(balance);
npx truffle exec --network rinkeby ./scripts/testnet.js

it give me balance 0

but my balance is 18.75 on rinkeby

ok, this way it works :

const { alchemyApiKey } = require('../secrets.json');
const providerUrl = `https://eth-rinkeby.alchemyapi.io/v2/${alchemyApiKey}`;

const accounts = await web3.eth.getAccounts();
console.log(accounts);

const ethers = require('ethers');
const provider =  new ethers.providers.JsonRpcProvider(providerUrl);
const balance = (await provider.getBalance(accounts[0])).toString();
console.log(balance);

but its not clean im using both web3 and ethers :confused:

lol ok, its simple as that :

const accounts = await web3.eth.getAccounts();
console.log(accounts);
const balance = await web3.eth.getBalance(accounts[0]);
console.log(balance);

I think it's because we provide, mnemonics and provider in truffle-config.js cool
but, why I dont need to require web3 please ?

it seems truffle use web3 and waffle use ethers :face_with_monocle:
my learn curve seems hard :face_with_thermometer: