OINDAO Docs
手册
手册
  • 手册
  • Use Cases
    • 区块链简介
      • 1 区块链历史
      • 2 WEB3简介
      • 3 行业发展与机遇
    • 产品UI/UX
      • 1 产品立项
      • 2 产品白模流程
      • 3 产品高保真流程
      • 4 需求文档规范
      • 5 UI/UX规范
      • 6 产品迭代示范
      • 7 支付及上线流程
    • 技术开发文档
      • 1 solidity
        • 1 开发环境
        • 2 常用调用工具
        • 3 语法引用链接等材料
      • 2 rust
        • 1 开发环境
        • 2 常用调用工具
        • 3 语法引用链接等材料
      • 3. 游戏框架
      • 4 热钱包框架原理
      • 5 ubantu服务器搭建
        • 1 以太节点搭建
        • 2 常规服务器搭建
    • 前端交互
      • 1 VUE快速指南及开发经验
        • Vue3 基础内容
        • Composition API
        • Vuex的使用方法
      • 2 react native快速指南以及开发经验
      • 3 各钱包插件前端交互
      • 4 APP打包技术HTML5方向
      • 5 K线插件技术
      • 6 游戏引擎技术
    • 测试与安全
    • 1 经典安全事故案例
    • 2 常规服务器对攻防检测手段列表
    • 3 合约安全注意规范
Powered by GitBook
On this page

Was this helpful?

  1. Use Cases
  2. 前端交互

2 react native快速指南以及开发经验

接入wallet connect

PreviousVuex的使用方法Next3 各钱包插件前端交互

Last updated 2 years ago

Was this helpful?

第一步:add dependencies: @walletconnect/react-native-dapp,以及walletconnect需要的依赖 @react-native-async-storage/async-storage(或者其他合适的storage)

第二步:在根目录加入文件global.ts

import { Platform, LogBox } from 'react-native'

export interface Global { btoa: any atob: any self: any Buffer: any process: any location: any }

declare var global: Global if (typeof global.self === 'undefined') { global.self = global }

if (Platform.OS !== 'web') { require('react-native-get-random-values') LogBox.ignoreLogs([ "Warning: The provided value 'ms-stream' is not a valid 'responseType'.", "Warning: The provided value 'moz-chunked-arraybuffer' is not a valid 'responseType'.", ]) }

global.btoa = global.btoa || require('base-64').encode global.atob = global.atob || require('base-64').decode

global.Buffer = require('buffer').Buffer

global.process = require('process') global.process.env.NODE_ENV = DEV ? 'development' : 'production' global.process.version = 'v9.40'

global.location = { protocol: 'https', }

第三步:如果是expo搭建的项目,需要在根目录加入metro.config.js

module.exports = { resolver: { extraNodeModules: require('expo-crypto-polyfills'), }, }

第四步:修改App.tsx, 用WalletConnectProvider包裹整个app

import './Global'

import WalletConnectProvider from '@walletconnect/react-native-dapp'

import AsyncStorage from '@react-native-async-storage/async-storage'

第五步:主要hook: useWalletConnect

踩坑经历:

  • 有可能遇到dependencies问题,尝试换npm, yarn reinstall node_modules

  • 如果有non-native dependencies, 可以用rn-nodeify 来hack modules

链接:

tutorials: 内容有部分outdated,但是大致思路可以借鉴

:

walletconnet 文档:

https://docs.walletconnect.com/quick-start/dapps/react-native
https://levelup.gitconnected.com/tutorial-how-to-set-up-web3js-1-x-with-react-native-0-6x-2021-467b2e0c94a4
https://gist.github.com/dougbacelar/29e60920d8fa1982535247563eb63766