솔라나 설치 설명 문서(Evernote)
솔라나 GIT
https://solscan.io/
BIP44 규격 m/44'/501'/0'/0'
Install rustc, cargo and rustfmt.
$ curl https://sh.rustup.rs -sSf | sh
$ source $HOME/.cargo/env
$ rustup component add rustfmt
$ rustup update
$ rustup install VERSION
$ sudo apt-get update
$ sudo apt-get install libssl-dev libudev-dev pkg-config zlib1g-dev llvm clang make
softwareupdate --install-rosetta
$ git clone https://github.com/solana-labs/solana.git
$ cd solana
$ cargo build
Binary 생성 확인
$ cd solana/target/debug/
$ ./solana --version
linux 환경에서 생성
$ mkdir ~/my-solana-wallet
$ cd solana/target/debug/
$ ./solana-keygen new --outfile ~/my-solana-wallet/my-keypair.json
$ ./solana-keygen pubkey ~/my-solana-wallet/my-keypair.json
결과 : Vhtqv2iFRNFMjuwTcNsC2VM16nTxkVJjRN4bQoVwvY9 지갑 주소 생성
my-keypair.json 안에 64byte 배열 생성됨 복구에 사용
web3.js 에서 생성
const wallet = web3.Keypair.generate();
key bytes 설정(복구)
const keypair_bytes = [0,0,0,0,0...0,0]; //total length : 64
var private_key_bytes = new Uint8Array(keypair_bytes.slice(0, 32))
var public_key_bytes = new Uint8Array(keypair_bytes.slice(32, keypair_bytes.length))
console.log("private_key_bytes ", private_key_bytes)
console.log("public_key_bytes ", public_key_bytes)
console.log(Keypair.fromSeed(private_key_bytes).publicKey.toString())
니모닉 설정(복구)
let mnemonic = "bid cloth bleak jaguar lens situate play gospel visual sweet west suit"
let pw = "";
bip39.mnemonicToSeed(mnemonic, pw).then((bytes) => {
const derivedSeed = ed25519.derivePath(derivePath, bytes.toString('hex')).key;
const keypair = Keypair.fromSeed(derivedSeed)
console.log("publickKey", keypair.publicKey.toString())
console.log("secretKey", keypair.secretKey)
})
솔라나 발송 정보
Create Simple Transaction
let transaction = new web3.Transaction();
Add an instruction to execute
transaction.add(web3.SystemProgram.transfer({
fromPubkey: payer.publicKey,
toPubkey: toAccount.publicKey,
lamports: 1000,
}));
토큰 발송관련 정보
const fromWallet = Keypair.fromSeed(private_key_bytes)
const toPublicKey = new PublicKey(toAddress)
const mint = new PublicKey('토큰주소 여기')
const token = new Token(connection, mint, TOKEN_PROGRAM_ID, fromWallet)
const fromTokenAccount = await token.getOrCreateAssociatedAccountInfo(fromWallet.publicKey)
const toTokenAccount = await token.getOrCreateAssociatedAccountInfo(toPublicKey)
transaction = new Transaction().add(
Token.createTransferInstruction(
TOKEN_PROGRAM_ID,
fromTokenAccount.address,
toTokenAccount.address,
fromWallet.publicKey,
[],
sendAmount * LAMPORTS_PER_SOL,
),
);
발송
Sign transaction, broadcast, and confirm
const signature = await sendAndConfirmTransaction(
connection,
transaction,
[fromWallet],
);