GithubHelp home page GithubHelp logo

near-ca's Introduction

NEAR Chain Abstraction Layer (NEAR-CA)

DISCLAIMER: This should only be used for educational purposes.

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 the NEAR blockchain.
  • Transaction signing and sending on the Ethereum blockchain.
  • Key derivation functions for cryptographic operations.
  • Support for EIP-1559 transactions on Ethereum.

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.

To install dependencies and set up the project:

# Install dependencies
yarn
# Credentials
cp .env.example .env  <---- paste your Near credentials
# Send Eth. You'll need to fund your account first. 
# More details in the 'Fund your account' part of this document 
npx ts-node examples/send-eth.ts

NEAR Credentials

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

Fund your account

Get your address

 ts-node examples/getEthAddress.ts

After getting your address fund it from one of your own wallets.

Examples

CLI

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

For more detailed examples, see the Examples README.

Frontend

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

yarn add near-ca

Example: Setup NearEthAdapter and Send ETH

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

import dotenv from "dotenv";
import {
  MultichainContract,
  NearEthAdapter,
  nearAccountFromEnv,
} from "near-ca";

dotenv.config();

const account = await nearAccountFromEnv();

const adapter = await NearEthAdapter.fromConfig({
  mpcContract: new MultichainContract(
    account,
    process.env.NEAR_MULTICHAIN_CONTRACT!
  ),
  derivationPath: "ethereum,1",
});

await adapter.signAndSendTransaction({
  receiver: "0xdeADBeeF0000000000000000000000000b00B1e5",
  amount: 1n,
  chainId: 11_155_111,
  // Optional: Set nearGas (default is 300 TGAS, which sometimes might not be sufficient)
});

near-ca's People

Contributors

bh2smith avatar sgerodes avatar microchipgnu avatar poppyseeddev avatar ppsimatikas avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.