Skip to content

Commit

Permalink
Add Examples Readme (#56)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Smith <[email protected]>
  • Loading branch information
poppyseedDev and bh2smith authored May 29, 2024
1 parent aefd9d5 commit f25a205
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 47 deletions.
89 changes: 42 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,66 @@

**DISCLAIMER: This should only be used for educational purposes.**

NEAR-CA is a TypeScript library that provides an abstraction layer for interacting with the NEAR blockchain. It simplifies the process of performing transactions and managing accounts on NEAR and Ethereum chains.

Intended to be used on server-side applications only.
NEAR-CA is a TypeScript library designed to provide an abstraction layer for interacting with the NEAR blockchain, simplifying the process of performing transactions and managing accounts on both NEAR and Ethereum chains. This library is intended for use in server-side applications only.

## Features

- Account management for NEAR blockchain.
- Transaction signing and sending on Ethereum blockchain.
- Account management for the NEAR blockchain.
- Transaction signing and sending on the Ethereum blockchain.
- Key derivation functions for cryptographic operations.
- Support for EIP-1559 transactions on Ethereum.

## Local Testing
## Contracts

### Get Started

This project requires Node.js version 20.0.0 or higher. If you are using nvm, you can run `nvm use` to use the node version specified in `.nvmrc`.

This project requires the Node.js version 20.0.0+.
If you are using nvm, you can run `nvm use` and use the node version in `.nvmrc`.
To install dependencies and set up the project:

```sh
# Install
# Install dependencies
yarn
# Credentials
cp .env.example .env <---- paste your Near credentials
# Buy NFT by collection slug:
npx ts-node examples/opensea.ts
# You will be prompted to provide a collectionSlug

# Set up credentials
cp .env.example .env # Paste your NEAR credentials into the .env file

# Run example scripts
npx ts-node examples/*.ts
```

## Installation
### NEAR Credentials

To install NEAR-CA, run the following command:
Before using NEAR-CA, ensure you have the following environment variables set:

```bash
yarn add near-ca
```
- `NEAR_ACCOUNT_ID`: Your NEAR account identifier.
- `NEAR_ACCOUNT_PRIVATE_KEY`: Your NEAR account private key.
- `NEAR_MULTICHAIN_CONTRACT`: The NEAR contract that handles multichain operations.

Copy the `.env.example` file and add these values to the `.env` file.

For setting up a wallet, use the NEAR testnet wallet. The testnet wallet is different from the main wallet. For example, you can use the [Mintbase Wallet](https://testnet.wallet.mintbase.xyz/).

## Usage
### Usage

For Ethereum, you can derive addresses, create payloads for transactions, and send signed transactions.

For more detailed examples, see the [Examples README](./examples/README.md).

## Frontend

### Get Started

To install NEAR-CA in your project, run the following command:

```bash
yarn add near-ca
```

### Example: Setup NearEthAdapter and Send ETH

Here's an example of how to set up the `NearEthAdapter` and send ETH:

```typescript
import dotenv from "dotenv";
import {
Expand All @@ -51,7 +71,7 @@ import {
} from "near-ca";

dotenv.config();
// Could also import and use nearAccountFromKeyPair here ;)

const account = await nearAccountFromEnv();

const adapter = await NearEthAdapter.fromConfig({
Expand All @@ -66,31 +86,6 @@ await adapter.signAndSendTransaction({
receiver: "0xdeADBeeF0000000000000000000000000b00B1e5",
amount: 0.00000001,
chainId: 11_155_111,
// Optional Set nearGas (default is 300 TGAS - which still sometimes doesn't work!)
// Optional: Set nearGas (default is 300 TGAS, which sometimes might not be sufficient)
});
```

### Other Examples

Each of the following scripts can be run with

```bash
npx ts-node examples/*.ts
```

1. [(Basic) Send ETH](./examples/send-eth.ts)
2. **WETH**
- [Deposit (aka wrap-ETH)](./examples/weth/wrap.ts)
- [Withdraw (aka unwrap-ETH)](./examples/weth/wrap.ts)
3. [Transfer ERC721](./examples/nft/erc721/transfer.ts)
4. [(Advanced) Buy NFT On Opensea](./examples/opensea.ts)

## Configuration

Before using NEAR-CA, ensure you have the following environment variables set:

- `NEAR_ACCOUNT_ID`: Your NEAR account identifier.
- `NEAR_ACCOUNT_PRIVATE_KEY`: Your NEAR account private key.
- `NEAR_MULTICHAIN_CONTRACT`: The NEAR contract that handles multichain operations.

Copy the `.env.example` file and place these values in `.env`
46 changes: 46 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
## Examples

You can run any of the following example scripts using the command:

```bash
npx ts-node examples/*.ts
```

Here are some of the available examples:

1. **Basic:**
- [Send ETH](./send-eth.ts)
2. **WETH Operations:**
- [Deposit (Wrap-ETH)](./weth/wrap.ts)
- [Withdraw (Unwrap-ETH)](./weth/unwrap.ts)
3. **NFT Operations:**
- [Transfer ERC721](./nft/erc721/transfer.ts)
4. **Advanced:**
- [Buy NFT on OpenSea](./opensea.ts)

## Example: Buy NFT by Collection Slug

To buy an NFT using a collection slug, follow these steps:

```sh
# Install dependencies
yarn

# Set up credentials
cp .env.example .env # Paste your NEAR credentials into the .env file

# Run the OpenSea example script
npx ts-node examples/opensea.ts
```

You will be prompted to provide a `collectionSlug`.

### What is a Collection Slug?

A collection slug identifies a specific collection on OpenSea. To find a collection slug:

1. Visit [testnet.opensea](https://testnets.opensea.io/).
2. Browse and find a collection you like.
3. Copy the slug from the URL: `https://testnets.opensea.io/collection/[slug]`.

For example, if the URL is `https://testnets.opensea.io/collection/the-monkey-chainz`, the collection slug is `the-monkey-chainz`.

0 comments on commit f25a205

Please sign in to comment.