- Blockchain By Example
- Bellaj Badr Richard Horrocks Xun (Brian) Wu
- 138字
- 2021-06-10 18:53:30
Preparation
Before you start building your program, make sure you have Node.js and NPM (short for Node Package Manager) installed.
In order to create an OP_RETURN transaction, we can use one of the many available bitcoin APIs, such as:
- bitcore (https://bitcore.io/)
- php-OP_RETURN (https://github.com/coinspark/php-OP_RETURN)
- python-OP_RETURN (https://github.com/coinspark/python-OP_RETURN)
In our example, we will use a JavaScript library called bitcoinjs-lib written for Node.js. We install the corresponding package as follows:
npm install bitcoinjs-lib --save
In the example code, we will submit requests using Node.js and the request package to access the API. Therefore, we install the following modules:
npm install request --save
npm install request-promise --save
Similar to the first method, we will use the first address and its corresponding private key generated by Electrum to send a raw transaction carrying a hello world message programmatically.