k7io
1
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
it seems to me that rinkeby does not offer the use of the ethers library by magic
Best Regards.
1 Like
k7io
2
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
k7io
3
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
k7io
4
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
my learn curve seems hard