Skip to main content

Neon Transfer Client

This page explains how to pass tokens between Solana and Neon EVM programmatically.

TL;DR

Introduction

This page describes how to use the Neon token pass tool: providing the same functionality as the NeonPass UI. The tool is an npm package that supports the transfer of SPL or ERC-20 tokens between Solana and Neon EVM.

Prerequisites

  • You need to integrate Solana-compatible and EVM-compatible wallet providers from supported official libraries such as @solana/web3.js or web3.js, ether.js and WalletConnect.

  • Supported browser plugins (e.g. Phantom or MetaMask wallets).

Step 1: Install and setup

1.1 Clone the repository

git clone https://github.com/neonlabsorg/neon-client-transfer.git

1.2 Install the package

yarn add neon-portal

1.3 Enable access to wallets

Next, create access for providers and connect wallets for Neon EVM and Solana networks.

note

The following example uses web3.js, but it is also possible to use alternatives.

import { clusterApiUrl } from '@solana/web3.js';
import Web3 from 'web3';

const SOLANA_DEVNET = clusterApiUrl('devnet');
const NEON_DEVNET = new Web3.providers.HttpProvider('https://devnet.neonevm.org');
const connection = new Connection(SOLANA_DEVNET, 'confirmed');
const web3 = new Web3(NEON_DEVNET);

// Simple way to use private keys for wallets
// For integration of browser ext., read official wallets docs.
const solanaWallet = Keypair.fromSecretKey(decode(`<your private Solana key>`));
const neonWallet = web3.eth.accounts.privateKeyToAccount(`<your private Neon EVM key>`);

1.4 Configure parameters

We employ the evmParams method from Neon EVM to obtain specific addresses and constants required for seamless operations.

const proxyApi = new NeonProxyRpcApi(urls);
// ...
const neonProxyStatus = await proxyApi.evmParams();
const neonEvmProgram = new PublicKey(neonProxyStatus.NEON_EVM_ID);
const neonTokenMint = new PublicKey(neonProxyStatus.NEON_TOKEN_MINT);
note

For testing, use NEON_TRANSFER_CONTRACT_DEVNET or NEON_TRANSFER_CONTRACT_MAINNET constants. These objects contain snapshots with the latest neonProxyStatus state.

Step 2: Transfer tokens

Transfer NEON

This example will generate a transaction to transfer NEON from Solana to Neon EVM. It utilizes the functions found in the neon-transfer.ts file.

const neonToken: SPLToken = {
...NEON_TOKEN_MODEL,
address_spl: proxyStatus.NEON_TOKEN_MINT,
chainId: CHAIN_ID
};
const transaction = await solanaNEONTransferTransaction(
solanaWallet,
neonWallet,
neonEvmProgram,
neonTokenMint,
neonToken,
amount
); // Solana Transaction object
transaction.recentBlockhash = (await connection.getLatestBlockhash('finalized')).blockhash; // Network blockhash
const solanaSignature = await sendSolanaTransaction(connection, transaction, [signer], false, {
skipPreflight: false
}); // method for sign and send transaction to network
console.log(solanaSignature);

Transfer ERC-20 tokens

When working with Devnet, Testnet, or Mainnet, different ERC-20 tokens are utilized. We maintain a JSON list of supported tokens. Alternatively, please refer to the token list.

To transfer ERC-20 tokens from Solana to Neon EVM, use the following patterns:

const token = tokenList[0];
const transaction = await neonTransferMintWeb3Transaction(
connection,
web3,
proxyApi,
proxyStatus,
neonEvmProgram,
solanaWallet,
neonWallet,
token,
amount
);
transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash;
const solanaSignature = await sendSolanaTransaction(connection, transaction, [signer], true, {
skipPreflight: false
});
console.log(solanaSignature);

Alternative libraries

We employ the web3.js library to streamline our code within the Neon Transfer codebase. However, you can opt for alternatives such as ethers.js, or WalletConnect.

React App

The following live demo with an open codebase supports the tooling via React App.

Was this page helpful?