How to use eosjs in react-native project?
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": "^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
To Reproduce Steps to reproduce the behavior: 1. import { Api, JsonRpc, RpcError } from 'eosjs'; import JsSignatureProvider from 'eosjs/dist/eosjs-jssig'; // development only 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

Same here.
react-native doesn't like JsSignatureProvider and instantiate Api doesn't work because JsSignatureProvider is required.
same problem
the same bug
The JsSignatureProvider won't work with React Native due to a dependency on the mobile-incompatible eosjs-ecc package. You could potentially write your own signature provider that utilizes a community-created eosjs-ecc-rn package found here. However, this has not been audited for security or performance implications so use at your own risk.