diff --git a/examples/oft-solana/README.md b/examples/oft-solana/README.md index 3e767ca57..89ae03ff3 100644 --- a/examples/oft-solana/README.md +++ b/examples/oft-solana/README.md @@ -79,29 +79,9 @@ We recommend that you request 5 devnet SOL, which should be sufficient for this cp .env.example .env ``` -In the `.env` just created, set `SOLANA_PRIVATE_KEY` to your private key value in base58 format. Since the locally stored keypair is in an integer array format, we'd need to encode it into base58 first. You can create a temporary script called `getBase58Pk.js` in your project root with the following contents: +In the `.env` just created, set `SOLANA_PRIVATE_KEY` to your private key value in base58 format. Since the locally stored keypair is in an integer array format, we'd need to encode it into base58 first. -
- View `getBase58Pk.js` script - -```js -import fs from "fs"; -import { Keypair } from "@solana/web3.js"; -import bs58 from "bs58"; - -const keypairFilePath = ``; // you can view this by running `solana config get` - -const data = fs.readFileSync(keypairFilePath, "utf8"); -const keypairJson = JSON.parse(data); -const keypair = Keypair.fromSecretKey(Uint8Array.from(keypairJson)); -const base58EncodedPrivateKey = bs58.encode(keypair.secretKey); - -console.log(base58EncodedPrivateKey); -``` - -Then, run `node getBase58Pk.js` - -
+You can run the `npx hardhat lz:solana:base-58` to output your private key in base58 format. Optionally, pass in a value for the `--keypair-file` flag if you want to use the keypair other than the default at `~/.config/solana.id.json` Also set the `RPC_URL_SOLANA_TESTNET` value. Note that while the naming used here is `TESTNET`, it refers to the [Solana Devnet](https://docs.layerzero.network/v2/developers/evm/technical-reference/deployed-contracts#solana-testnet). We use `TESTNET` to keep it consistent with the existing EVM testnets. diff --git a/examples/oft-solana/hardhat.config.ts b/examples/oft-solana/hardhat.config.ts index 4653a746f..e298b44c3 100644 --- a/examples/oft-solana/hardhat.config.ts +++ b/examples/oft-solana/hardhat.config.ts @@ -61,7 +61,7 @@ const config: HardhatUserConfig = { networks: { 'sepolia-testnet': { eid: EndpointId.SEPOLIA_V2_TESTNET, - url: process.env.RPC_URL_SEPOLIA || 'https://rpc.sepolia.org/', + url: process.env.RPC_URL_SEPOLIA || 'https://gateway.tenderly.co/public/sepolia', accounts, }, hardhat: { diff --git a/examples/oft-solana/tasks/index.ts b/examples/oft-solana/tasks/index.ts index 30d3f0c4a..9008859b3 100644 --- a/examples/oft-solana/tasks/index.ts +++ b/examples/oft-solana/tasks/index.ts @@ -6,5 +6,6 @@ import './solana/createOFTAdapter' import './solana/sendOFT' import './solana/setAuthority' import './solana/getPrioFees' +import './solana/base58' import './solana/setInboundRateLimit' import './solana/setOutboundRateLimit' diff --git a/examples/oft-solana/tasks/solana/base58.ts b/examples/oft-solana/tasks/solana/base58.ts new file mode 100644 index 000000000..9e4191c02 --- /dev/null +++ b/examples/oft-solana/tasks/solana/base58.ts @@ -0,0 +1,36 @@ +import assert from 'assert' +import fs from 'fs' +import path from 'path' + +import { Keypair } from '@solana/web3.js' +import bs58 from 'bs58' +import { task } from 'hardhat/config' + +import { types as devtoolsTypes } from '@layerzerolabs/devtools-evm-hardhat' + +interface Base58FeesTaskArgs { + /** + * The path to the keypair file to be used. + */ + keypairFile: string +} + +assert(process.env.HOME != undefined, 'process.env.HOME needs to be defined') + +const defaultKeypairFile = path.resolve(process.env.HOME, '.config/solana/id.json') + +task('lz:solana:base-58', 'Outputs the base58 string for a keypair') + .addParam( + 'keypairFile', + 'The path to the keypair file to be used. Defaults to ~/.config/solana/id.json', + defaultKeypairFile, + devtoolsTypes.string + ) + .setAction(async ({ keypairFile }: Base58FeesTaskArgs) => { + assert(fs.existsSync(keypairFile), `Keypair file not found: ${keypairFile}`) + const data = fs.readFileSync(keypairFile, 'utf8') + const keypairJson = JSON.parse(data) + const keypair = Keypair.fromSecretKey(Uint8Array.from(keypairJson)) + const base58EncodedPrivateKey = bs58.encode(keypair.secretKey) + console.log(base58EncodedPrivateKey) + })