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

In the RN, api.query.xxx, api.tx.xxx, undefined is not a object. #526

Closed
0xthreebody opened this issue Jan 1, 2019 · 10 comments
Closed
Labels
Bug Tracks issues causing errors or unintended behavior, critical to fix for reliability.

Comments

@0xthreebody
Copy link

nodeJs console.log(api); :

api:---- ApiPromise {
  _eventemitter: EventEmitter { _events: { error: [EE] }, _eventsCount: 1 },
  _extrinsics:
   { timestamp: { set: [Function] },
     consensus:
      { reportMisbehavior: [Function],
        noteOffline: [Function],
        remark: [Function],
        setHeapPages: [Function],
        setCode: [Function],
        setStorage: [Function] },
     balances: { transfer: [Function], setBalance: [Function] },
     session:
      { setKey: [Function],
        setLength: [Function],
        forceNewSession: [Function] },
     staking:
      { stake: [Function],
        unstake: [Function],
        nominate: [Function],
        unnominate: [Function],
        registerPreferences: [Function],
        setSessionsPerEra: [Function],
        setBondingDuration: [Function],
        setValidatorCount: [Function],
        forceNewEra: [Function],
        setOfflineSlashGrace: [Function] },
     democracy:
      { propose: [Function],
        second: [Function],
        vote: [Function],
        startReferendum: [Function],
        cancelReferendum: [Function],
        cancelQueued: [Function] },
     council:
      { setApprovals: [Function],
        reapInactiveVoter: [Function],
        retractVoter: [Function],
        submitCandidacy: [Function],
        presentWinner: [Function],
        setDesiredSeats: [Function],
        removeMember: [Function],
        setPresentationDuration: [Function],
        setTermDuration: [Function] },
     councilVoting:
      { propose: [Function],
        vote: [Function],
        veto: [Function],
        setCooloffPeriod: [Function],
        setVotingPeriod: [Function] },
     councilMotions: { propose: [Function], vote: [Function] },
     grandpa: { reportMisbehavior: [Function] },
     treasury:
      { proposeSpend: [Function],
        setPot: [Function],
        configure: [Function],
        rejectProposal: [Function],
        approveProposal: [Function] },
     contract: { call: [Function], create: [Function] },
     upgradeKey: { upgrade: [Function], setKey: [Function] },
     sudo: { sudo: [Function], setKey: [Function] } },
  _genesisHash:
 ... ...

It's complete.

But the RN console.log(api); :

01-01 16:48:57.505  3704  3735 I ReactNativeJS: 'api:-------', { _eventemitter: 
01-01 16:48:57.505  3704  3735 I ReactNativeJS:    { _events: { error: { fn: [Function], context: [Circular], once: true } },
01-01 16:48:57.505  3704  3735 I ReactNativeJS:      _eventsCount: 1 },
01-01 16:48:57.505  3704  3735 I ReactNativeJS:   _extrinsics: {},
01-01 16:48:57.505  3704  3735 I ReactNativeJS:   _genesisHash: {},
01-01 16:48:57.505  3704  3735 I ReactNativeJS:   _query: 
01-01 16:48:57.505  3704  3735 I ReactNativeJS:    { substrate: 
01-01 16:48:57.505  3704  3735 I ReactNativeJS:       { code: 
01-01 16:48:57.505  3704  3735 I ReactNativeJS:          { [Function: decorated]
01-01 16:48:57.505  3704  3735 I ReactNativeJS:            at: [Function],
01-01 16:48:57.505  3704  3735 I ReactNativeJS:            meta: 
01-01 16:48:57.505  3704  3735 I ReactNativeJS:             { documentation: 
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                [ { '0': 'W',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '1': 'a',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '2': 's',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '3': 'm',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '4': ' ',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '5': 'c',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '6': 'o',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '7': 'd',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '8': 'e',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '9': ' ',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '10': 'o',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '11': 'f',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '12': ' ',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '13': 't',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '14': 'h',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '15': 'e',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '16': ' ',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '17': 'r',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '18': 'u',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '19': 'n',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '20': 't',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '21': 'i',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '22': 'm',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '23': 'e',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '24': '.' },
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                  _Type: [Function: Text] ],
01-01 16:48:57.505  3704  3735 I ReactNativeJS:               modifier: { raw: 0, _enum: [ 'None', 'Default', 'Required' ] },
01-01 16:48:57.505  3704  3735 I ReactNativeJS:               type: 
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                { raw: 
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                   { '0': 'B',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                     '1': 'y',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                     '2': 't',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                     '3': 'e',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                     '4': 's',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                     _originalLength: 6 },
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                  _def: 
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                   { Type: [Function: Type],
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                     'StorageFunctionType$Map': [Function: StorageFunctionType$Map] },
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                  _index: 0,
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                  _indexes: [ 0, 1 ] },
01-01 16:48:57.505  3704  3735 I ReactNativeJS:               toJSON: [Function: toJSON] },
01-01 16:48:57.505  3704  3735 I ReactNativeJS:            method: 'code',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:            section: 'substrate',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:            toJSON: [Function] },
01-01 16:48:57.505  3704  3735 I ReactNativeJS:         heapPages: 
01-01 16:48:57.505  3704  3735 I ReactNativeJS:          { [Function: decorated]
01-01 16:48:57.505  3704  3735 I ReactNativeJS:            at: [Function],
01-01 16:48:57.505  3704  3735 I ReactNativeJS:            meta: 
01-01 16:48:57.505  3704  3735 I ReactNativeJS:             { documentation: 
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                [ { '0': 'N',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '1': 'u',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '2': 'm',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '3': 'b',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '4': 'e',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '5': 'r',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '6': ' ',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '7': 'o',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '8': 'f',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '9': ' ',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '10': 'w',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '11': 'a',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '12': 's',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '13': 'm',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '14': ' ',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '15': 'l',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '16': 'i',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '17': 'n',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '18': 'e',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '19': 'a',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '20': 'r',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '21': ' ',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '22': 'm',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '23': 'e',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '24': 'm',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '25': 'o',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '26': 'r',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '27': 'y',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '28': ' ',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '29': 'p',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '30': 'a',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '31': 'g',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '32': 'e',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '33': 's',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '34': ' ',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '35': 'r',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '36': 'e',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '37': 'q',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '38': 'u',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '39': 'i',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '40': 'r',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '41': 'e',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '42': 'd',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '43': ' ',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '44': 'f',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '45': 'o',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '46': 'r',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '47': ' ',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '48': 'e',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '49': 'x',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '50': 'e',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '51': 'c',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '52': 'u',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '53': 't',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '54': 'i',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '55': 'o',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '56': 'n',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '57': ' ',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '58': 'o',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '59': 'f',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '60': ' ',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '61': 't',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '62': 'h',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '63': 'e',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '64': ' ',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '65': 'r',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '66': 'u',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '67': 'n',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '68': 't',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '69': 'i',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '70': 'm',
01-01 16:48:57.505  3704  3735 I ReactNativeJS:                    '7

It‘s incomplete, so.. such as api.query.xxxx, api.extrinsics, api.tx, and more, can't to be working.
_ _20181222002106

@jacogr
Copy link
Member

jacogr commented Jan 2, 2019

Only on Android. I think this is the metadata parsing going wrong, quite possibly related to the polyfill for u8a to string which is used in this environment.

@jacogr
Copy link
Member

jacogr commented Jan 2, 2019

Can you just double check that the API versions dor the desktop and RN match up as well? (There has been a breaking metadata change at the end of last year, so if the node is recent, just need to make sure the API has support for it)

@0xthreebody
Copy link
Author

@jacogr I tested the RN @polkadot/api version: 0.35.19; // have the same issue.
the NodeJs @polkadot/api version is: 0.35.19; // It's working ok. (got the Alice account balance.)
the substrate node version is : version 0.9.1-b98d3b87-x86_64-linux-gnu, (Commits on Dec 29, 2018);

@jacogr
Copy link
Member

jacogr commented Jan 2, 2019

Brilliant, thanks. Ok, I will take a look into the decoding then, somewhere the decoding polyfill (TextDecoder) is not playing along would be my guess.

@0xthreebody
Copy link
Author

Does the IOS running the api.query.balances.freebalance() is ok? Not have this issue?

@jacogr
Copy link
Member

jacogr commented Jan 2, 2019

On iOS only tested subscribe on new head and the extracting the block. I will extend that example with more. (It could still be an issue, untested as you suggested so I just don’t know - however it is much saner with encoders and Uint8Array, so may be fine)

@jacogr jacogr added Bug Tracks issues causing errors or unintended behavior, critical to fix for reliability. @api labels Jan 3, 2019
@jacogr
Copy link
Member

jacogr commented Jan 3, 2019

iphone x - 11 4 2019-01-03 13-49-46

The above is with the RN sample in https://github.com/jacogr/pjs-rn-rncli updated to also display balances. So it really seems to point to (another) Android-specific issue.

Additionally, have checked the TextEncoder/TextDecoder polyfills (by only using them) and it does the correct thing, so it does not point to that area either. So will have to do a bit more digging, somewhere in the Uint8Array handling Android is not too happy.

@0xthreebody
Copy link
Author

@jacogr
Copy link
Member

jacogr commented Jan 7, 2019

For future reference - the current JSC version inside RN Android is from 2014, so areas like Uint8Array is not supported. (For iOS the on-device JSC is used, so any recent 10.x+ is ok)

The RN team is looking to upgrade to track actual recent versions, for now installing the above package and removing the (not-quite-working Uint8Array polyfills) does the trick. (I need to update my sample repo to reflect that) Hopefully the issue will be addressed in a new RN update soon.

@polkadot-js-bot
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Jun 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Tracks issues causing errors or unintended behavior, critical to fix for reliability.
Projects
None yet
Development

No branches or pull requests

3 participants