Game-X-Coin / eosjs-rn

General purpose library for the EOS blockchain.
http://eosio.github.io/eosjs
MIT License
18 stars 5 forks source link

How to use eosjs-rn in react-native project? #10

Closed marcoLuo closed 5 years ago

marcoLuo commented 5 years ago

react-native version 0.57.8 package.json content { "name": "eosjsTest", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" }, "dependencies": { "react": "16.6.3", "react-native": "0.57.8", "eosjs-rn": "^20.0.0-beta3" }, "devDependencies": { "babel-jest": "23.6.0", "jest": "23.6.0", "metro-react-native-babel-preset": "0.51.1", "react-test-renderer": "16.6.3" }, "jest": { "preset": "react-native" } }

Version of EOSJS 20.0.0-beta3

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. import { Api, JsonRpc, RpcError } from 'eosjs-rn'; import JsSignatureProvider from 'eosjs-rn/dist/eosjs-jssig'; import { TextEncoder, TextDecoder } from 'text-encoding';

  2. const defaultPrivateKey = "5JtUScZK2XEp3g9gh7F8bwtPTRAkASmNrrftmx4AxDKD5K4zDnr"; const signatureProvider = new JsSignatureProvider([defaultPrivateKey]); const rpc = new JsonRpc('http://127.0.0.1:8888', { fetch }); const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() }); (async () => { const result = await api.transact({ actions: [{ account: 'eosio.token', name: 'transfer', authorization: [{ actor: 'useraaaaaaaa', permission: 'active', }], data: { from: 'useraaaaaaaa', to: 'useraaaaaaab', quantity: '0.0001 SYS', memo: '', }, }] }, { blocksBehind: 3, expireSeconds: 30, }); console.dir(result); })();

Expected behavior can not run correctly

Screenshots 2018-12-25 20-50-17

jadertao commented 5 years ago

I try to reproduce this issue according your package.json but failed. Everything works good for me. try to remove all node_modules and run yarn cache clean reinstall again.

I think there is some problems with node_modules/base-x, check out its version which in my test project is 3.0.5(both in node_modules/base-x/package.json and yarn.lock) and it works well with react-native and eosjs-rn.

marcoLuo commented 5 years ago

eosjsTest.zip it's my react-native project, can you give me a hand? @JadeTao

marcoLuo commented 5 years ago

check out its version which in my test project my base-x verion is also 3.0.5

jadertao commented 5 years ago

eosjsTest.zip it's my react-native project, can you give me a hand? @JadeTao

hey, this projects uses eosjs. I can run it smoothly after I switch to eosjs-rn instead.

marcoLuo commented 5 years ago

. i can run it smoothly on IOS, but failed on Andriod

jadertao commented 5 years ago

still ok with Android Simulator Google Nexus 5X -6.0.0- API 23 with eosjs-rn

marcoLuo commented 5 years ago

can you speak chinese? use wechat? haha~ @JadeTao

jadertao commented 5 years ago

you can send me ur wechat via email

marcoLuo commented 5 years ago

you can send me ur wechat via email

ok, thanks

marcoLuo commented 5 years ago

you can send me ur wechat via email

i have sent email to you but not respond, did you received the email?

jadertao commented 5 years ago

email

no...and I test my google mail. it works.

jadertao commented 5 years ago

I have figured out this problem. It is because base-x v3.0.5 use Uint8Array#fill method, which is not supported in JavaScriptCore(the react native javascript engine). And the temporary solution is:

  1. add "base-x": "3.0.4" to your package.json.
  2. re-install node modules.
  3. run npm ls base-x. make sure there is no base-x@3.0.5. btw. base-x is planning to revert to es5.

related issue: https://github.com/uport-project/react-native-uport-connect/issues/10 https://github.com/cryptocoinjs/base-x/issues/51

—— update: i'm confused too. i can use Uint8Array in my own project but can't in this test project. i don't know why.

jadertao commented 5 years ago

core-js helps out. just import 'core-js' in the 1st line of index.js.

marcoLuo commented 5 years ago

core-js helps out. just import 'core-js' in the 1st line of index.js.

it also helps me out. tks