-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples/oft-solana): have base58 script as hardhat task instead (…
- Loading branch information
Showing
4 changed files
with
40 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) |