Node, CommonJS
Last updated
Was this helpful?
Last updated
Was this helpful?
This guide is tailored for developers working in a NodeJS environment, specifically those who are using the CommonJS module system. We'll walk you through the installation process and show you how to get started with creating and signing a Bitcoin SV transaction using the SDK. Whether you're building on BSV for the first time or transitioning an existing project to use the SDK, this guide is for you.
Before we begin, make sure you have Node.js installed on your system. You can download and install Node.js from . This guide assumes you have basic knowledge of JavaScript and the Node.js environment.
First, you'll need to install the BSV SDK package in your project. Open your terminal, navigate to your project directory, and run the following command:
This command installs the BSV SDK in your project, making it ready for use. There are no external runtime dependencies.
To use the BSV SDK in a NodeJS project with CommonJS, you'll import modules using the require
syntax. Here's how you set up a basic script to use the BSV SDK:
Create a new JavaScript file in your project. For example, index.js
.
At the top of your file, require the SDK modules you plan to use. For instance:
Now, let's create and sign a transaction. We'll follow the example provided in the README. This example demonstrates how to create a transaction from a source to a recipient, including calculating fees, signing the transaction, and broadcasting it to ARC.
Copy and paste the following code into your index.js
file below your require
statement:
This script demonstrates the entire process of creating a transaction, from initializing keys to signing and broadcast. When you run this script using Node.js (replacing the source transaction, private key, and ARC credentials), the spend will be signed and broadcast to the BSV network.
To run your script, simply execute the following command in your terminal:
Congratulations! You've successfully installed the BSV SDK in your NodeJS project and created a signed transaction. This guide covered the basics to get you started, but the BSV SDK is capable of much more. Explore the SDK documentation for detailed information on all the features and functionalities available to build scalable applications with the BSV blockchain.