This article assumes you:
- Already have a basic understanding of Solana
- Have basic experience using Anchor programming
- Have installed the Solana-related command-line tools
- Have a Ledger hardware wallet
-
Check the Ledger's Wallet ID
- When you connect multiple Ledgers to the same computer, you can use the Wallet ID to specify which Ledger wallet to use
- If you only plan to use a single Ledger on the computer, you do not need to include the Wallet ID
solana-keygen pubkey usb://ledger
-
Check the SOL wallet address
- Command line to check the SOL wallet:
# Check the 1st address solana-keygen pubkey usb://ledger?key=0/0 # Check the 2nd address solana-keygen pubkey usb://ledger?key=1/0 # Check the 3rd address solana-keygen pubkey usb://ledger?key=2/0
- The command line needs to specify the keypair URL, formatted as
usb://ledger?key=<DERIVATION_PATH>
- If there are multiple Ledgers, you need to specify the WALLET_ID, which would be
usb://ledger/<WALLET_ID>?key=<DERIVATION_PATH>
- If there are multiple Ledgers, you need to specify the WALLET_ID, which would be
- The
DERIVATION_PATH
is used to maintain consistency with the Phantom wallet, usingx/0
, so that when the Ledger connects to the Phantom wallet, it displays the same address as in the command line - The Keypair URL parameter is ignored in ZSH, and you need to modify
~/.zshrc
to add a lineunsetopt nomatch
-
If there are multiple Ledgers, you can reverse query the WALLET_ID based on the keypair URL, for example:
solana resolve-signer usb://ledger?key=1/0 # DwWogDGHNM5wNxcwjkroMeK83NTLpZ7ZtEbtCSrxMKNZ is your WALLET_ID usb://ledger/DwWogDGHNM5wNxcwjkroMeK83NTLpZ7ZtEbtCSrxMKNZ?key=1'/0'
-
Set the Solana network
- Here I set it to localhost, but you can also set it to devnet and mainnet-beta based on actual usage
- First, start a test validator locally as the localhost network
pkill solana-test-validator rm -rf test-ledger/ solana-test-validator
- Set the Solana network and default wallet
# network can be mainnet-beta, testnet, devnet, localhost export network=localhost solana config set --url $network # Set my local ~/.config/solana/id.json as the default wallet, which will be used later solana config set --keypair ~/.config/solana/id.json solana config get
-
Use a regular keypair hot wallet to create a buffer account
- Why use a regular keypair hot wallet first? Because
- Deploying a Solana contract requires putting program bytecode on-chain, with a maximum of 1K per transaction, usually requiring over 500 transactions, which may result in:
- The Ledger wallet cannot handle it, pressing several hundred to a thousand times is almost impossible
- The Ledger wallet does not support this method of deploying contracts
- The console will output the buffer account address BUFFER_ADDRESS
solana program write-buffer target/deploy/curve_launchpad.so \ --keypair ~/.config/solana/id.json Buffer: 3qMNULQwNWQPKKT29WPmjnfSbcpXCFSoYwZg5yLCbwty # If you want to delete the buffer account and retrieve SOL solana program close -k ~/.config/solana/id.json --buffers
- Why use a regular keypair hot wallet first? Because
-
Transfer buffer authority to the Ledger wallet
- Execute the command line
solana program set-buffer-authority <BUFFER_ADDRESS> \ --new-buffer-authority <LEDGER_PUBKEY> For example, if the Ledger wallet address is LdJx7GAVbb9JhaPMvLEDEZb3Fjk16Bv5R4f8qzMUQeG, the command line would be: solana program set-buffer-authority 3qMNULQwNWQPKKT29WPmjnfSbcpXCFSoYwZg5yLCbwty \ --new-buffer-authority LdJx7GAVbb9JhaPMvLEDEZb3Fjk16Bv5R4f8qzMUQeG Account Type: Buffer Authority: LdJx7GAVbb9JhaPMvLEDEZb3Fjk16Bv5R4f8qzMUQeG
-
Next, you can use the Ledger to deploy the Solana program
- Use the Ledger wallet to deploy the contract, using the bytecode from the buffer account
- Here, usb://ledger?key=0/0 corresponds to the address LdJx7GAVbb9JhaPMvLEDEZb3Fjk16Bv5R4f8qzMUQeG, which is set as the upgrade authority for the Solana program
solana program deploy \ --program-id target/deploy/curve_launchpad-keypair.json \ --buffer 3qMNULQwNWQPKKT29WPmjnfSbcpXCFSoYwZg5yLCbwty \ --upgrade-authority usb://ledger?key=0/0 Program Id: AAR4w5eyv8JXrDvmB1EJE9QmxP24KaPyRUiZU5M8pAeZ Signature: ua19eg9EQFcgTKVn5ZHjL1JB3s4mPYYUC7f4At6bnoXSrTKqm3RZABj3JbcwtsjUYEFTrS6bCGet6SUr2PaCyyk
- Query the program status
solana program show AAR4w5eyv8JXrDvmB1EJE9QmxP24KaPyRUiZU5M8pAeZ Program Id: AAR4w5eyv8JXrDvmB1EJE9QmxP24KaPyRUiZU5M8pAeZ Owner: BPFLoaderUpgradeab1e11111111111111111111111 ProgramData Address: 8nH1bnwoqbuipTWaX25pg6tDWfvDoFs1yErFTCFR39SB Authority: LdJx7GAVbb9JhaPMvLEDEZb3Fjk16Bv5R4f8qzMUQeG # upgrade authority Last Deployed In Slot: 937 Data Length: 506936 (0x7bc38) bytes Balance: 3.52947864 SOL
-
If the contract has already been deployed, you can use the Ledger to upgrade the Solana program
- First, use a regular keypair wallet buffer account
solana program write-buffer target/deploy/curve_launchpad.so \ --keypair ~/.config/solana/id.json Buffer: 9suJnc9cY7ZFiNPe39me1wsNqxsM9HnrokouNTnqWVV
- Then transfer the buffer authority to the Ledger wallet
solana program set-buffer-authority <BUFFER_ADDRESS> \ --new-buffer-authority <LEDGER_PUBKEY> For example solana program set-buffer-authority 9suJnc9cY7ZFiNPe39me1wsNqxsM9HnrokouNTnqWVV \ --new-buffer-authority LdJx7GAVbb9JhaPMvLEDEZb3Fjk16Bv5R4f8qzMUQeG Account Type: Buffer Authority: LdJx7GAVbb9JhaPMvLEDEZb3Fjk16Bv5R4f8qzMUQeG
- Use the Ledger wallet to upgrade the program, where <PROGRAM_ADDRESS> specifies the Program Id to be upgraded, which here is AAR4w5eyv8JXrDvmB1EJE9QmxP24KaPyRUiZU5M8pAeZ
solana program deploy --program-id <PROGRAM_ADDRESS> \ --buffer <BUFFER_ADDRESS> \ --upgrade-authority <LEDGER_PUBKEY> For example solana program deploy \ --program-id AAR4w5eyv8JXrDvmB1EJE9QmxP24KaPyRUiZU5M8pAeZ \ --buffer 9suJnc9cY7ZFiNPe39me1wsNqxsM9HnrokouNTnqWVV \ --upgrade-authority usb://ledger?key=0/0 Program Id: AAR4w5eyv8JXrDvmB1EJE9QmxP24KaPyRUiZU5M8pAeZ Signature: 2zgdmJGwHwEogZArPnL9zju6LtJqXpCgTHtMw78aUmXEmgJEgi5tdFQPFNSNzoVk7cqLxVWBthoSQa1dZRqMzUvQ
- Check the program status
solana program show AAR4w5eyv8JXrDvmB1EJE9QmxP24KaPyRUiZU5M8pAeZ Program Id: AAR4w5eyv8JXrDvmB1EJE9QmxP24KaPyRUiZU5M8pAeZ Owner: BPFLoaderUpgradeab1e11111111111111111111111 ProgramData Address: 8nH1bnwoqbuipTWaX25pg6tDWfvDoFs1yErFTCFR39SB Authority: LdJx7GAVbb9JhaPMvLEDEZb3Fjk16Bv5R4f8qzMUQeG # upgrade authority Last Deployed In Slot: 1474 Data Length: 506936 (0x7bc38) bytes Balance: 3.52947864 SOL
Reference: