Last updated
Was this helpful?
Last updated
Was this helpful?
We're using on a local machine, once you're ready to start, initialize a project with npm init -y
and install the BSV Blockchain official SDK.
To create your first transcation you need to send some BSV into a locking script you control. Let's set up our local node.js environment with a key we can use.
Run the above code by copying it into createKey.js
and running node createKey.js
Now you should get something in your console which looks like this:
To continue developing and testing, this address will require some funding. This can be done by sending BSV to this wallet, and due the low cost of transactions only a few satoshis will suffice ($0.01 equivalent is recommended). This way, you also ensure that you're not affected if you would lose access to the keys.
Once mined, a green button which says "Raw Tx" will be visible, which allows you to download the full transaction bytes as a hex string file. That's going to be our sourceTransaction which will fund the transaction we are going to define with the SDK. Copy the hex string into a file in the working directory called .transactions
. The file contents should look something like this:
You can then construct your first transaction by copying the code below into createTx.js
and running node createTx.js
.
You should see a response like this:
You're a BSV Developer.
You can keep running the same script - it will keep appending new transactions to the .transactions
file until you run out of funds. BSV is so cheap that this could be a few thousand transactions later.
In the mean time, you can create your own Bitcoin ScriptTemplates by defining your own classes like so:
To create this output you simply add the class to an output:
Unlocking it in a future transaction you can simply do:
To check that the script works you can then run:
For more guidance from the documentation - jump here.
If you don't have any BSV, you can find out how to buy it , or ask the BSV community on or to send you some funding.
Once you've sent an initial funding transaction to this address, grab the whole transaction from by pasting in the txid
to the search box.
Ask the AI if you want to learn more, or if you need help from a human. If you want to contribute new ScriptTemplates of your own design there's a .