Skip to content

Using wallet-address-validator with React Native #59

@dbhalling

Description

@dbhalling

I was trying to use wallet-address-validator with React Native. Below is the solution I found. If you know a better solution that would be great. I thought other people might be interested in this issue.

Here are the steps to install wallet-address-validator with React Native and Expo

  1. yarn add wallet-address-validator

  2. npm install -g browserify

  3. Create a file wav-in.js that imports the wallet-address-validator module and simply exports it:

    var WAValidator = require('wallet-address-validator');
    module.exports = WAValidator;

  4. Then in the terminal in the project

    browserify cwav-in.js -o wav.js

  5. This will result in an error if you put in the test code below from Wallet-Address-validator in App.js

var WAValidator = require('wallet-address-validator');

var valid = WAValidator.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'BTC');
if(valid)
console.log('This is a valid address');
else
console.log('Address INVALID');

  1. You will however, get an error along the lines “… is not a function”

  2. On line 3837 of wav.js change “var WAValidator = require('wallet-address-validator');” to “WAValidator = require('wallet-address-validator');”

  3. On the very last line in of wav.js add “module.exports = WAValidator;”

everything should be working now

You can find a basic React Native with wallet-address-validator app at https://github.com/dbhalling/WAValidatorRN

This medium article is on point https://hackernoon.com/using-core-node-js-modules-in-react-native-apps-64acd4d07140

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions