1

is there any thing connect to whisper(web3.shh) protocol in react-native. How to connect REACT-NATIVE with whisper ethereum protocol using GETH or any light Client or API

1
  1. Add web3js to react-native:

    yarn add web3@1.0.0-beta.34

1.0.0-beta.34 works well in react-native environment for me. I want very lucky with newer bersions.

  1. Run Geth with --rpcapi shh --shh parameter to turn Whisper on.
  2. Use something like this in your class:
this.web3 = new Web3(new Web3.providers.WebsocketProvider('ws://127.0.0.1:8546'));
...

let postData = {
            ttl: 2000,
            topic: defaultTopic,
            powTarget: 0.2,
            powTime: 20,
            payload: encodeToHex(JSON.stringify({
                _id: this.state.username,
                text: messages[0].text,
                name: this.state.username,
            })),
            symKeyID: some symKey,
            sig: some asymKeyId,
        };

this.web3.shh.post(postData);

let options = {
            topics: [defaultTopic],
            symKeyID: some symKey
        };
this.web3.shh.subscribe('messages', options)
                    .on('data', (message) => { ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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