I'm looking to deploy a regular solana program written in Rust (not anchor) on mainnet. For some reason I can't rewrite it using anchor solana. I have searched online and all failed. Does anyone know the detailed answer?
2 Answers
You use cargo build-sbf
or cargo build-bpf
(depending on you used version) to build your program. That will build a .so
file in your target/deploy
directory. From there you can use the solana program deploy
command to deploy your program. To see relevant info about that run solana program deploy --help
.
Run
cargo build-sbf
orcargo build-bpf
(depending on version) to build your program. That will build a.so
file intarget/deploy
directory.To deploy on mainnet, you need a wallet containing real SOL. Copy wallet private key
and paste it in the javascript code below
const bs58 = require('bs58')
const fs = require('fs')
b = bs58.decode(
'your private key'
)
j = new Uint8Array(
b.buffer,
b.byteOffset,
b.byteLength / Uint8Array.BYTES_PER_ELEMENT
)
fs.writeFileSync('key.json', `[${j}]`)
Try run above code to create
key.json
fileRun
solana config set --url https://api.mainnet-beta.solana.com
Run
solana program deploy -k *path_to_key.json* *path_to_.so_file*