@solana/web3.js를 사용하여 솔라나 계정 생성하기 (in React native)
- 필요한 라이브러리를 설치한다.
npm i @solana/web3.js react-native-get-random-values react-native-url-polyfill
- babel.config.js를 다음과 같이 수정한다.
module.exports = {
presets: [
[
'module:metro-react-native-babel-preset',
{unstable_transformProfile: 'hermes-stable'},
],
],
};
- 프로젝트 최상단 (index.js)에 다음과 같이 설정한다.
import 'react-native-get-random-values';
import 'react-native-url-polyfill/auto';
- 설정이 끝난뒤 다음과 같이 계정을 생성할 수 있다.
import * as solanaWeb3 from '@solana/web3.js';
const keypair = solanaWeb3.Keypair.generate(); // 랜덤 생성
// solanaWeb3.Keypair.fromSecretKey 또는 solanaWeb3.Keypair.fromSeed으로도 생성 가능
const solanaConnection = new solanaWeb3.Connection(solanaWeb3.clusterApiUrl('devnet'));
const balance = await solanaConnection.getBalance(keyPair.publicKey);
console.log(`잔액 : ${balance / solanaWeb3.LAMPORTS_PER_SOL} SOL`);
https://solanacookbook.com/integrations/react-native.html#install-dependencies
React Native | Solana Cookbook
React Native and Solana React Native is an open-source UI software framework used to develop mobile, web and desktop applications by enabling developers to use the React framework along with native platform capabilities. Powered with the Solana SDK, this i
solanacookbook.com
https://yihau.github.io/solana-web3-demo/tour/create-keypair.html
Create Keypair | Solana Web3 Example
Create Keypair Private Key import { Keypair } from "@solana/web3.js"; import * as bs58 from "bs58"; (async () => { { const keypair = Keypair.generate(); console.log(`public key: ${keypair.publicKey.toBase58()}`); console.log(`private key(raw): ${keypair.se
yihau.github.io