Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update readme header and links #23

Merged
merged 1 commit into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 20 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,23 @@ Eventually most of these will end up in `@solana/web3.js`.

## What can I do with this module?

[Make multiple keypairs at once](#makekeypairs-amount)
[Make multiple keypairs at once](#makekeypairs)

[Resolve a custom error message](#getcustomerrormessageprogramerrors-errormessage)
[Resolve a custom error message](#getcustomerrormessage)

[Get an airdrop if your balance is below some amount, and wait until it's confirmed](#airdropifrequiredconnection-publickey-lamports-maximumbalance)
[Get an airdrop if your balance is below some amount, and wait until it's confirmed](#airdropifrequired)

[Get a Solana Explorer link for a transaction, address, or block](#getexplorerlinktype-identifier-clustername)
[Get a Solana Explorer link for a transaction, address, or block](#getexplorerlink)

[Make a bunch of keypairs at once](#makekeypairs-amount)
[Confirm a transaction (includes getting a recent blockhash)](#confirmtransaction)

[Make a bunch of keypairs at once](#makekeypairs-amount)
[Get a transaction's logs](#getlogs)

[Confirm a transaction (includes getting a recent blockhash)](#confirmtransaction-connection-transaction)
[Get a keypair from a keypair file (like id.json)](#getkeypairfromfile)

[Get a transaction's logs](#getlogs-connection-transaction)
[Get a keypair from an environment variable](#getkeypairfromenvironment)

[Get a keypair from a keypair file (like id.json)](#getkeypairfromfilename)

[Get a keypair from an environment variable](#getkeypairfromenvironmentenvironmentvariable)

[Add a new keypair to an env file](#addkeypairtoenvfilekeypair-environmentvariable-file)
[Add a new keypair to an env file](#addkeypairtoenvfile)

## Installation

Expand All @@ -36,15 +32,15 @@ npm i @solana-developers/helpers

## helpers for the browser and node.js

### makeKeypairs(amount)
### makeKeypairs

In some situations - like making tests for your on-chain programs - you might need to make lots of keypairs at once. You can use `makeKeypairs()` combined with JS destructuring to quickly create multiple variables with distinct keypairs.

```typescript
const [sender, recipient] = makeKeypairs(2);
```

### getCustomErrorMessage(programErrors, errorMessage)
### getCustomErrorMessage

Sometimes Solana transactions throw an error with a message like:

Expand Down Expand Up @@ -102,7 +98,7 @@ And `errorMessage` will now be:
"This token mint cannot freeze accounts";
```

### airdropIfRequired(connection, publicKey, lamports, maximumBalance)
### airdropIfRequired

Request and confirm an airdrop in one step. As soon as the `await` returns, the airdropped tokens will be ready in the address, and the new balance of tokens is returned. The `maximumBalance` is used to avoid errors caused by unnecessarily asking for SOL when there's already enough in the account, and makes `airdropIfRequired()` very handy in scripts that run repeatedly.

Expand All @@ -117,7 +113,7 @@ const newBalance = await airdropIfRequired(
);
```

### getExplorerLink(type, identifier, clusterName)
### getExplorerLink

Get an explorer link for an `address`, `block` or `transaction` (`tx` works too).

Expand Down Expand Up @@ -147,7 +143,7 @@ getExplorerLink("block", "241889720", "mainnet-beta");

Will return `"https://explorer.solana.com/block/241889720"`

### makeKeypairs(amount)
### makeKeypairs

Particularly in tests, Solana developers often need to make multiple keypairs at once. So just:

Expand All @@ -157,15 +153,15 @@ const [alice, bob, tokenA, tokenB] = makeKeypairs(4);

And you'll now have `alice`, `bob`, `tokenA` and `tokenB` as distinct keypairs.

### confirmTransaction(connection, transaction)
### confirmTransaction

Confirm a transaction, and also gets the recent blockhash required to confirm it.

```typescript
await confirmTransaction(connection, transaction);
```

### getLogs(connection, transaction)
### getLogs

Get the logs for a transaction signature:

Expand All @@ -186,7 +182,7 @@ This a good way to assert your onchain programs returned particular logs during

## node.js specific helpers

### getKeypairFromFile(filename)
### getKeypairFromFile

Gets a keypair from a file - the format must be the same as [Solana CLI](https://docs.solana.com/wallet-guide/file-system-wallet) uses, ie, a JSON array of numbers:

Expand All @@ -208,15 +204,15 @@ or using home dir expansion:
const keyPair = await getKeypairFromFile("~/code/solana/demos/steve.json");
```

### getKeypairFromEnvironment(environmentVariable)
### getKeypairFromEnvironment

Gets a keypair from a secret key stored in an environment variable. This is typically used to load secret keys from [env files](https://stackoverflow.com/questions/68267862/what-is-an-env-or-dotenv-file-exactly).

```typescript
const keyPair = await getKeypairFromEnvironment("SECRET_KEY");
const keypair = await getKeypairFromEnvironment("SECRET_KEY");
```

### addKeypairToEnvFile(keypair, environmentVariable, file)
### addKeypairToEnvFile

Saves a keypair to the environment file.

Expand Down
Loading