Skip to content

Commit

Permalink
feat(examples/oft-solana): have base58 script as hardhat task instead (
Browse files Browse the repository at this point in the history
  • Loading branch information
nazreen authored Dec 11, 2024
1 parent e90a1d3 commit 1c8681e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
24 changes: 2 additions & 22 deletions examples/oft-solana/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<details>
<summary> View `getBase58Pk.js` script </summary>

```js
import fs from "fs";
import { Keypair } from "@solana/web3.js";
import bs58 from "bs58";

const keypairFilePath = `<KEYPAIR_FILE_PATH_HERE>`; // 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`

</details>
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.

Expand Down
2 changes: 1 addition & 1 deletion examples/oft-solana/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
1 change: 1 addition & 0 deletions examples/oft-solana/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
36 changes: 36 additions & 0 deletions examples/oft-solana/tasks/solana/base58.ts
Original file line number Diff line number Diff line change
@@ -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)
})

0 comments on commit 1c8681e

Please sign in to comment.