New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

near-ca

Package Overview
Dependencies
Maintainers
0
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

near-ca

An SDK for controlling Ethereum Accounts from a Near Account.

  • 0.9.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
695
increased by40.4%
Maintainers
0
Weekly downloads
 
Created
Source

NEAR Chain Abstraction Layer (NEAR-CA)

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

  • EVM Account Derivation from NEAR blockchain.
  • Transaction signing and sending on the Ethereum blockchain.
  • Key derivation functions for cryptographic operations.
  • Support for EIP-1559 transactions on Ethereum.
  • Wallet Connect intergration tools.

Usage

CLI

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

For more detailed usage examples, see the Examples README.

Integrations

near-safe extends this tool kit by using the EOA as an owner of an ERC-4337 Safe account.

Frontend/UI

Install near-ca, 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 {
  broadcastSignedTransaction,
  convertToAction,
  isRlpHex,
  setupAdapter,
  signatureFromOutcome,
} from "near-ca";

dotenv.config();
const { NEAR_ACCOUNT_ID, NEAR_ACCOUNT_PRIVATE_KEY } = process.env;

const adapter = await setupAdapter({
  accountId: NEAR_ACCOUNT_ID!,
  mpcContractId: MPC_CONTRACT_ID!,
  // privateKey: NEAR_ACCOUNT_PRIVATE_KEY!, // Optional depending on setup
});

const {
  evmMessage,
  nearPayload: { receiverId, actions },
} = await evm.encodeSignRequest({
  method: "eth_sendTransaction",
  chainId: 11_155_111, // Sepolia
  params: [
    {
      from: evm.address,
      to: "0xdeADBeeF0000000000000000000000000b00B1e5",
      value: "0x01", // 1 WEI
      // data: "0x", // Optional
    },
  ],
});
console.log(`Requesting Signature for ${evmMessage}`);
// Using your near Account, send the nearPaylod as signature request:
const nearAccount = adapter.nearAccount();
//
const outtcome = await nearAccount.signAndSendTransaction({
  receiverId,
  actions: actions.map((a) => convertToAction(a)),
});
const signature = signatureFromOutcome(outtcome);
console.log("Signature aquired!");
if (isRlpHex(evmMessage)) {
  // This will be true for what we built above.
  broadcastSignedTransaction({ transaction: evmMessage, signature });
} else {
  // Use Signature for whatever else.
}

Other Examples (CLI)

These examples require Private Key to be supplied:

Each of the following scripts can be run with

npx tsx examples/*.ts
  1. (Basic) Send ETH
  2. WETH
  3. Transfer ERC721
  4. (Advanced) Buy NFT On Opensea

Configuration

Before using NEAR-CA, ensure you have the following environment variables set in your .env file:

  • NEAR_ACCOUNT_ID: Your NEAR account identifier.
  • NEAR_ACCOUNT_PRIVATE_KEY: Your NEAR account private key.
  • MPC_CONTRACT_ID: The NEAR contract that handles multichain operations.
  • NETWORK: Either near or testnet.

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

Steps to get your NEAR_ACCOUNT_ID and NEAR_ACCOUNT_PRIVATE_KEY:

  1. Create a Near wallet address, super easy, here: https://wallet.bitte.ai/
  2. Your XYZ.near is your NEAR_ACCOUNT_ID.
  3. Visit Settings Page
  4. Go to "Security & Recovery" -> "Export Account".
  5. After the exporting is complete click on "Private Key" and copy it.
  6. Paste it to NEAR_ACCOUNT_PRIVATE_KEY in your .env file.

Keywords

FAQs

Package last updated on 11 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc