@levain/wallet-sdk
TypeScript icon, indicating that this package has built-in type declarations

37.0.0 • Public • Published

Levain TypeScript SDK

npm downloads per month

Levain allows you to start, run and grow your crypto business with enterprise-grade security and self-custody wallet infrastructure.

This is the official Levain SDK for TypeScript. It provides a set of tools to interact with the Levain GraphQL API easily. For the complete Levain GraphQL API documentation, refer to the Levain developer docs.

Installation

We recommend using pnpm to install the package. If you don't have it installed, you can install it by following the instructions here.

To install the Levain TypeScript SDK, run the following command:

pnpm install @levain/wallet-sdk

Examples

For complete examples, refer to the Developer Guides section within the Levain developer docs. You will find examples using Levain SDK, together with using the Levain GraphQL API directly if there isn't a corresponding SDK method.

Creating wallet example

import { generate } from '@levain/levain-client-keygen';

const accessToken = 'lvp_M71B0IVbFyAl5sg6uPkaPP0K9LBOyN4xWRkRhiHXkXcb0fe265';
const orgId = '000000000000';
const organizationNetworkId = '8accb40f-aa7d-483d-b82b-55852cbb321f';
const walletPassword = '<your wallet password here>';

const client = new LevainGraphClient({
  accessToken: 'lvp_ZaWT5JxWACwFBzj5VMSsqZ0Kfxo8BzLxnVYZca28OFb5713bb5',
  url: 'https://app.levain.tech/graphql',
});

// Create gas tank
const gasTank = await client.createGasTank({
  orgId,
});

// Fund gas tank

// Create keys
const mainKey = generate(walletPassword);
const backupKeyPair = generate(walletPassword);

const key1 = await client.createKey({
  orgId,
  type: KeyType.ScalarNeutered,
  publicKey: mainKey.publicKey,
  retrieveIfExists: false,
});
const key2 = await client.createKey({
  orgId,
  type: KeyType.ScalarNeutered,
  publicKey: backupKeyPair.publicKey,
  retrieveIfExists: false,
});
const key3 = await client.createKey({ orgId, type: KeyType.Rsa, retrieveIfExists: false });

// Create wallet
const wallet = await client.createWallet({
  orgId,
  organizationNetworkId,
  type: WalletType.EvmContractSafe, // or WalletType.EvmContractSimpleMultiSig,
  name: 'My new wallet',
  mainKey: {
    keyId: key1.keyId,
    passwordRecoveryKeyId: key3.keyId,
    encryptedPrivateKey: mainKey.encryptedPrivateKey,
  },
  backupKey: {
    keyId: key2.keyId,
  },
});

console.log(wallet); // { walletId: "de96428b-cd1b-4643-b62d-e2dfb2953897" }

Executing transaction example

const accessToken = 'lvp_M71B0IVbFyAl5sg6uPkaPP0K9LBOyN4xWRkRhiHXkXcb0fe265';
const orgId = '000000000000';
const ethNetworkAssetId = '41928452-cf9c-4e53-9bb5-caa5d1d367d5';
const walletId = '12b10782-d3fb-49fe-8cce-872bb7ea8d74';
const walletAddress = '0xf05A37144AcbFCBF3747E1EF4dCA8ee84f960Bad';
const walletPassword = '<your wallet password here>';

const client = new LevainGraphClient({
  accessToken,
  url: '/graphql',
});

// Fund your wallet with sufficient funds and whitelist the destination address first

// Create transaction request
const txRequest = await client.createTransactionRequest({
  walletId,
  networkAssetId: ethNetworkAssetId, // For custom transactions, omit `networkAssetId` and input `data` instead
  destinationAddress: walletAddress,
  amount: '0.1',
  gasLimit: 100_000,
});

// Approve transaction
await client.approveTransactionRequest({
  transactionRequestId: txRequest.requestId,
});

// Create transaction digests after approval quorum has been met
const txDigest = await client.createTransactionDigests({
  orgId,
  walletId,
  requestId: txRequest.requestId,
});

// Execute transaction
const executedTransaction = await client.executeTransaction({
  walletId,
  orgId,
  requestId: txRequest.requestId,
  digests: [
    {
      digest: txDigest.digest,
      digestId: txDigest.digestId,
    },
  ],
  walletPassword,
});

console.log(executedTransaction); // { transactionHash: "0xfdd6039a143e654f0131a1e1baba954ba1258f29675ddaae19e22d00608b45cf" }

Deposit address example

const accessToken = 'lvp_M71B0IVbFyAl5sg6uPkaPP0K9LBOyN4xWRkRhiHXkXcb0fe265';
const walletId = '12b10782-d3fb-49fe-8cce-872bb7ea8d74';
const erc20Address = '0x9aE64687D1ddD9c08aCD3d62A0d2f3af6cC350D4';

const client = new LevainGraphClient({
  accessToken: 'lvp_ZaWT5JxWACwFBzj5VMSsqZ0Kfxo8BzLxnVYZca28OFb5713bb5',
  url: '/graphql',
});

// Create deposit address
const depositAddress = await client.createWalletDepositAddress({
  walletId,
  label: 'My new address',
  toAutoDeploy: false,
});

// Deploy deposit address
await client.deployWalletDepositAddress({
  walletId,
  walletDepositAddressId: depositAddress.walletDepositAddressId,
});

// Wait for minimum network block confirmations

// Flush balance of a single ERC20 token from the deposit address to the main address
await client.flushWalletDepositAddress({
  walletId,
  erc20Address,
  walletDepositAddressId: depositAddress.walletDepositAddressId,
});

Readme

Keywords

none

Package Sidebar

Install

npm i @levain/wallet-sdk

Weekly Downloads

875

Version

37.0.0

License

none

Unpacked Size

462 kB

Total Files

35

Last publish

Collaborators

  • levaintech-bot
  • fuxingloh