Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

L2 balance return as 0 when sending MANA #4

Open
mfmcmillian opened this issue Jun 11, 2022 · 2 comments
Open

L2 balance return as 0 when sending MANA #4

mfmcmillian opened this issue Jun 11, 2022 · 2 comments

Comments

@mfmcmillian
Copy link

mfmcmillian commented Jun 11, 2022

This is the code I'm using, I've tried different wallet combinations, but I cant get the balance to return or make any transactions.

import { matic } from '@dcl/l2-scene-utils'
...
const balance = await matic.balance('0xFE2d424AF0Df49Bb3316cB2E9f574b0D09cf98Ad')
              log(balance)
              if(balance.l2 > 1) {
                matic.sendMana(`0xFE2d424AF0Df49Bb3316cB2E9f574b0D09cf98Ad`, 1).then(
                  () => {
                    player.pet3InventoryCount.increase(1)
                    createPhoenix();
                    player.writeDataToServer();
                  },
                  (error) => {
                    log("error", error)
                  }
                )

I've done the correct installations and installed all dependencies mentioned in the documentation.
Ive also confirmed I have over 3 MANA on the poly network.

@HPrivakos
Copy link
Contributor

HPrivakos commented Jun 21, 2022

Hey!
This has been fixed in the @next version, please use this code instead:

import * as l2 from '@dcl/l2-scene-utils'
import * as ethConnect from 'eth-connect'

...

const { mana } = await l2.createComponents()
const balanceWei = await mana.balance('0xFE2d424AF0Df49Bb3316cB2E9f574b0D09cf98Ad')
log(balanceWei)
if (new ethConnect.BigNumber(ethConnect.fromWei(balanceWei, 'ether')).comparedTo(new ethConnect.BigNumber(1)) >= 0) {
  mana
    .transfer(`0xFE2d424AF0Df49Bb3316cB2E9f574b0D09cf98Ad`, new ethConnect.BigNumber(ethConnect.toWei(1, 'ether')))
    .then(
      () => {
        player.pet3InventoryCount.increase(1)
        createPhoenix()
        player.writeDataToServer()
      },
      (error) => {
        log('error', error)
      }
    )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@mfmcmillian @HPrivakos and others