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

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

Closed
marcoLuo opened this issue Dec 25, 2018 · 14 comments
Closed

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

marcoLuo opened this issue Dec 25, 2018 · 14 comments

Comments

@marcoLuo
Copy link

marcoLuo commented Dec 25, 2018

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

@marcoLuo marcoLuo changed the title How to use eosjs-rn for react-native project? How to use eosjs-rn in react-native project? Dec 25, 2018
@jadertao
Copy link

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
Copy link
Author

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

@marcoLuo
Copy link
Author

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

@jadertao
Copy link

jadertao commented Jan 1, 2019

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
Copy link
Author

marcoLuo commented Jan 2, 2019

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

@jadertao
Copy link

jadertao commented Jan 2, 2019

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

@marcoLuo
Copy link
Author

marcoLuo commented Jan 2, 2019

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

@jadertao
Copy link

jadertao commented Jan 2, 2019

you can send me ur wechat via email

@marcoLuo
Copy link
Author

marcoLuo commented Jan 2, 2019

you can send me ur wechat via email

ok, thanks

@marcoLuo
Copy link
Author

marcoLuo commented Jan 3, 2019

you can send me ur wechat via email

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

@jadertao
Copy link

jadertao commented Jan 3, 2019

email

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

@jadertao
Copy link

jadertao commented Jan 3, 2019

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
cryptocoinjs/base-x#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
Copy link

jadertao commented Jan 4, 2019

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

@marcoLuo
Copy link
Author

marcoLuo commented Jan 4, 2019

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

it also helps me out. tks

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

2 participants