1.7.0 • Published 10 months ago

@cryptoscan/swap-sdk v1.7.0

Weekly downloads
-
License
-
Repository
-
Last release
10 months ago

@cryptoscan/swap-sdk

The fastest way to swap any tokens on any networks & dexes

[GitHub] [Our website] [Docs] [Discord]

Supported networks

  • Solana

Networks are planned to support: https://api.cryptoscan.pro/v1/networks

Get started

To install package:

npm install @cryptoscan/swap-sdk

Easy-To-Use Example

import { getWallet } from '@cryptoscan/solana-wallet-sdk';
import { swap } from '@cryptoscan/swap-sdk';

const secretKeyStr = 'YOUR_SECRET_KEY';
const wallet = getWallet(secretKeyStr);
const from = 'sol';
const to = 'HJAoYbnsf16Z8ftk3SsuShKLQQgzmxAPu41RTpjjpump';
const amount = 0.05;

swap({
  wallet,
  from,
  to,
  amount,
})
.then((tx) => console.log(tx))

Primary Usage

import { Keypair, Connection } from "@solana/web3.js";
import sendTransaction from '@cryptoscan/solana-send-transaction';
import { createTransaction } from '@cryptoscan/swap-sdk';

const rpcUrl = 'https://api.mainnet-beta.solana.com';
const wsRpcUrl = 'wss://api.mainnet-beta.solana.com';
const secretKeyStr = 'YOUR_SECRET_KEY';
const wallet = Keypair.fromSecretKey(bs58.decode(secretKeyStr));
const from = 'sol';
const to = 'HJAoYbnsf16Z8ftk3SsuShKLQQgzmxAPu41RTpjjpump';
const amount = 0.05;

async function swap() {
  const connection = new Connection(rpcUrl, {
    wsEndpoint: wsRpcUrl,
  })
  const transaction = await createTransaction({
    walletAddress: wallet.publicKey.toString(),
    from,
    to,
    amount,
  });

  if (transaction instanceof Error) {
    return transaction;
  }

  transaction.sign([wallet]);

  return sendTransaction(transaction, { connection }) // The fast Cryptoscan method
  // return connection.sendTransaction(transaction); // Solana SDK Method
}

swap().then((tx) => console.log(tx));

Swap Docs

  • wallet - Keypair of the wallet
  • from - Coin address to pay (Defaults: sol)
  • service - Platform to buy (Optional: auto-detecting)
  • to - Coin address to buy
  • amount - Amount of Coin from to buy
  • fee - Transaction fee (Optional)
  • priorityFee - Priority fee (Default: 0.0001)
  • slippage - Slippage (Default: 1)

FAQ

Yes. You don't share private key through api request. You sign transaction with private key locally only.

We charge a 0.39% fee on each successful transaction instruction. If you want to decrease fee - please contact us in discord or telegram We can increase fee down to 0.1% if you will contribute us.

You can create pull requests or make a project based on our packages. You have chance to get some supply for a work and get fee reduced for the api.

Contribute

To install dependencies:

npm install

To build:

npm build
1.7.0

10 months ago

1.6.3

1 year ago

1.6.2

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

1.5.0

1 year ago

1.4.2

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago

0.0.15

1 year ago

0.0.14

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago