Skip to content

someone please explain what gregory said at 1:44:58 to 1:45:12, why passing accounts around like that? #16

@elvisisvan

Description

@elvisisvan

what he said word-by-word:
"let's do the exactly same thing, say accounts, await, window, ethereum request get accounts and we're gonna set the accounts to the first account on the list, and then that's gonna set it the in component state of the parent component and we're gonna pass it back in here with this account like this

related code snippets:
App.js

...
function App() {
  const [account, setAccount] = useState(null)

  const loadBLockchainData = async () => {
    const provider = new ethers.providers.Web3Provider(window.ethereum)
     
  }

  useEffect(() => {
    loadBLockchainData()
  })

  return (
    <div>

    <Navigation account={account} setAccount={setAccount}/>

      <div className='cards__section'>

        <h3>Welcome to Millow</h3>

      </div>

    </div>
  );
}
...

Navigation.js

...
const Navigation = ({ account, setAccount }) => {
    const connectHandler = async () =>{
        const accounts = await window.ethereum.request({method: 'eth_requestAccounts'});
        setAccount(accounts[0])        
    }
...

video: https://youtu.be/C4blK6X-D_4?t=6298

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions