Develop for Gno using your app's native language
We created a Javascript object helper (useGno) that wraps the RPC API. The
useGno object is defined in the GnoNative repo at /expo/src/hooks/use-gno.ts
.
The RPC API documentation is avalaible in the Buf registry:
Please follow the general Build instructions
in the main
README and then:
make asdf.install_tools
npx create-expo-app my-app
cd my-app
npm install @berty/gnonative
We prepared for you an example Hello World code.
Open App.js and replace the content by this:
import React, { useEffect, useState } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import * as Gnonative from '@berty/gnonative';
export default function App() {
const gno = Gnonative.useGno();
const [greeting, setGreeting] = useState('');
useEffect(() => {
const greeting = async () => {
try {
// sync Hello function
setGreeting(await gno.hello('Gno'));
// async Hello function
for await (const res of await gno.helloStream('Gno')) {
console.log(res.greeting);
}
} catch (error) {
console.log(error);
}
};
greeting();
}, []);
return (
<View style={styles.container}>
<Text>Hey {greeting}</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
# Re-generate the native project directories from scratch
npx expo prebuild --clean
# Run the example app on Android
npx expo run:android
# Run the example app on iOS
npx expo run:ios
For bare React Native projects, you must ensure that you have
installed and configured the expo
package
before continuing.