eosjs icon indicating copy to clipboard operation
eosjs copied to clipboard

How to use eosjs in react-native project?

Open marcoLuo opened this issue 7 years ago • 4 comments

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 2018-12-25 20-58-59

marcoLuo avatar Dec 25 '18 12:12 marcoLuo

Same here.

react-native doesn't like JsSignatureProvider and instantiate Api doesn't work because JsSignatureProvider is required.

eedsilva avatar Dec 25 '18 19:12 eedsilva

same problem

blueplanet avatar Dec 28 '18 09:12 blueplanet

the same bug

anonymoustoken avatar Dec 29 '18 08:12 anonymoustoken

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.

c0d3ster avatar Jan 11 '19 22:01 c0d3ster