3

Can someone share an example of EOS blockchain integration with react-native? I am new to EOS development and I am struggling to integrate it in react-native app, there are always some missing dependencies or libraries.. Any help, link, tutorial or just code would be very helpful!

2 Answers 2

2

The EvaCoop-Team forked eosjs to make it more compatible with react-native. Async handling in react-native is a big mess with the original eosjs.

Here's the link to the git react-native-eos which also contains examples.

8
  • Thank you @cmadh, I saw the react-native-eos git but I had some difficulties connecting my application to the blockchain and I switch to only eosjs. I am currently stuck with eosjs npm package issues, so I will try again with react-native-eos and I will keep you posted. Commented Mar 15, 2019 at 18:56
  • can you post some of the errors you have?
    – cmadh
    Commented Mar 15, 2019 at 20:14
  • Hello @cmadh, currently I am getting: TypeError: Cannot read property 'setUrl' of undefined This error is located at: in App (at renderApplication.js:35) in RCTView (at View.js:45) in View (at AppContainer.js:98) in RCTView (at View.js:45) in View (at AppContainer.js:115) in AppContainer (at renderApplication.js:34) Commented Mar 17, 2019 at 13:42
  • Solved it and currently I am having Error: Failed to connect to /127.0.0.1:8888 while using ReactNativeEos.setUrl('http', '127.0.0.1', 8888); and ReactNativeEos.pushAction. Any thoughts ? Commented Mar 17, 2019 at 19:54
  • 1
    I'm guessing that should point to a EOS node, put in the address of a block producer instead of localhost perhaps, like eos.greymass.com or nodes.get-scatter.com Commented Mar 17, 2019 at 22:07
1

If you just want to read data you can use the EOS RPC API. Then you can use the Fetch API (for React Native) to connect to it promised based.

Your code could look something like this to read from a table of a contract.

fetch(<http://{host}:{port}/v1/chain/get_table_rows>, {
  method: 'POST',
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    code: <name of the smart contract>,
    table: <The name of the table to query>
}),
}).then(
 (result) => {
   // do something with result.json()
   // which will look like this
   // {
   // "rows": [
   //   {
   //     "account": "account",
   //     "balance": 1000
   //   }
   // ],
   // "more": false
   //}
 }
)
3
  • Thank you for your response @TeeAtack42 I already opened issue here: github.com/EvaCoop/react-native-eos/issues/4 because I am using react-native-eos, but it seems that I am not going to get anything in response. However, my idea is to have local node and be able to transfer coins from one to another account that is registered on the network using react-native. Commented Mar 20, 2019 at 20:23
  • Ok. I have looked into your GitHub issue. Have you tried varying the url? I think localhost/127.0.0.1:8888 seems to be referring to your local machine twice. Maybe try to remove the localhost and place an empty string.
    – tmm
    Commented Mar 21, 2019 at 9:06
  • A little bit late.. I tried it but it didn't helped so I switched to REACTJS only and everything works fine by now. Thanks for helping guys. Commented Mar 26, 2019 at 19:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.