🔗btc

Description

The transfer function is an asynchronous function that facilitates the transfer of a specified value of a cryptocurrency (Bitcoin) from one address to another.

Parameters

ParameterData TypeDescription

privateKey

string

The private key of the sender's address, required to sign the transaction and prove ownership of the funds.

value

string

The amount of Bitcoin to be transferred.

receiver

string

The address of the recipient where the funds will be transferred.

env

string

The environment or network in which the transaction will be executed (e.g., 'mainnet', 'testnet', etc.).

address

string

The sender's address from which the funds will be transferred.

ecc

any

An object representing the elliptic curve cryptography (ECC) implementation or library used for key operations.

Response

FieldData TypeDescription

tx

any

The transaction object that contains the necessary information for the transfer, such as inputs, outputs, and transaction details.

toSign

any

Data that needs to be signed by the private key to generate valid signatures. This typically includes transaction information and script data.

signatures

any

Signatures generated by the private key for the transaction. These signatures are used to verify the authenticity and authorization of the sender.

pubkeys

any

Public keys associated with the private key used to generate the signatures. These are used to verify the signatures and ensure they correspond to the correct private key and address.

Example Request and Response

Prerequisites

Before making requests with Nest SDK, you must have it installed.

You can install Nest SDK using either npm or yarn. Use the following commands to install Nest SDK:

npm install @nest25/wallet-lib
OR
yarn add @nest25/wallet-lib

Request

Here is an example of how to make a transfer request using the Nest SDK:

// import Nest SDK
import { Wallet } from 'nest25/wallet-lib';

// Create a new instance of the Wallet class
const wallet = new Wallet();
// test mnemonic for BTC mainnet (use the createWallet function to get one)
const testMnemonic = 'divorce poverty spend fire symbol market good skull rebel surge giggle album';
// receiver address
const receiver = '0xd040591F093eacFAB8734350aac24703a0081f29';

const main = async () => {
  // transfer 0.001 BTC from the test mnemonic to the receiver address
  const response = await wallet.transfer('btc',testMnemonic,receiver,'0.001');
  // print the response
  console.log(response);
};

main();

Response

 {
        code: 1,
        result: '5oWsXKXkTYxWUeBtyhaC6xxx7ZNRXW5qq1PJpbas1y4zQqgD9mxPGBF2zCeUkVHornFDo63hriUdVGuPp49u5Tvy'
      }

Use Cases

  • Transfer Bitcoin: The transfer function can be used to transfer a specific amount of Bitcoin from one address to another. It requires the private key of the sender's address, the amount to be transferred, the recipient's address, the desired environment (e.g., testnet or mainnet), the sender's address, and the ECC object for cryptographic operations.

  • Error Handling: The function handles potential errors during the transfer process. If any step fails, an error object with a code and description is returned, indicating the cause of the failure.

Last updated