Node.Js generates Bitcoin address (with code)
This time I will bring you Node.Js to generate a Bitcoin address (with code). What are the precautions for generating a Bitcoin address with Node.Js? Here is a practical case, let’s take a look.
Use Node.js, IDE uses sublime 3.
var randomBytes = require('randombytes') var BigInteger = require('bigi') var ecurve = require('ecurve') var crypto = require('crypto') var cs = require('coinstring') var secp256k1 = ecurve.getCurveByName('secp256k1') var randombytes = randomBytes(32).toString('hex') var privateKey = new Buffer(randombytes, 'hex') console.log("私钥:" + privateKey.toString('hex')) var ecparams = ecurve.getCurveByName('secp256k1') var curvePt = ecparams.G.multiply(BigInteger.fromBuffer(privateKey)) var x = curvePt.affineX.toBuffer(32) var y = curvePt.affineY.toBuffer(32) var publicKey = Buffer.concat([new Buffer([0x04]), x, y]) console.log("标准地址:" + publicKey.toString('hex')) //compressed publicKey = curvePt.getEncoded(true) //true forces compressed public key console.log("compressed:" + publicKey.toString('hex')) var sha = crypto.createHash('sha256').update(publicKey).digest() var pubkeyHash = crypto.createHash('rmd160').update(sha).digest() // pubkeyHash of compressed public key console.log("pubkeyHash:" + pubkeyHash.toString('hex')) // address of compressed public key console.log("压缩地址:" + cs.encode(pubkeyHash, 0x0)) //<-- 0x0 is for public addresses //这里还缺失校验和Base58编码 console.log(cs.encode(privateKey, 0x80)) //<--- 0x80 is for private addresses console.log(cs.encode(Buffer.concat([privateKey, new Buffer([0])]), 0x80)) // <-- compressed private address
Generate Bitcoin address
1. Generate a random private key. The private key is a 32-byte number. For example:
8F72F6B29E6E225A36B68DFE333C7CE5E55D83249D3D2CD6332671FA445C4DD3
2. Elliptic curve calculation public key After generating the private key, we use the elliptic curve encryption algorithm (ECDSA-secp256k1) to calculate the uncompressed public key corresponding to the private key. The generated public key is 65 bytes in total. First The first byte is 0x04, the last 32 bytes are the X coordinate, and the last 32 bytes are the Y coordinate: Public key P. DB985072968C72B036ED97BA2EF2DECE2ABCA5BE14792
Public key:
0459DEE66AB619C4A9E215D070052D1AE3A2075E5F58C67516B2E4884A88C79BE9A5FA8CCD255FB0A7A75DB985072968C72B036ED97BA2EF2DECE2ABCA5BE14 792
##ae9c74647a8c2f50fd832e397e36dbad05d86db3fe3d959a7c8a07c1ddda40c63. Calculate the SHA-256 hash value of the public key
4. Calculate the RIPEMD-160 hash value05f9d05358aab2a28f19910036e67a7295b14aac
5. Add the address version number (Bitcoin mainnet 0x00)0005f9d05358aab2a28f19910036e67a7295b14aac
In fact, this is almost the same, which is the compressed address finally generated by the above code. But in actual Bitcoin, verification must be added
6. Calculate the SHA-256 hash value
##9f35b0c37977a302512c22f586dd8da4ae1d20399f2ad3f75df23fbc024b4b2d
7. Calculate the SHA-256 hash value again
4b4f9bc87616687957db64efaf4efb2c00d1d93d549a0b70b15812936046d0ac8. Take the first 4 bytes of the previous step result (8-digit hexadecimal System)
4b4f9bc89. Add these 4 bytes to the end of the compression address generated in step 5
0005f9d05358aab2a28f19910036e67a7295b14aac4b4f9bc810. Use Base58 encoding
Base58 consists of 1-9 and English characters except i, l, 0, o. Base58 encode the result of the previous step and get:
1YbeKoyePe8gxyAYh4E3Qyqb15Nnepmod
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other php Chinese websites related articles!Recommended reading:
String array deduplication practical case analysis
How express mock operates front and backend parallel development
The above is the detailed content of Node.Js generates Bitcoin address (with code). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Applying for the Huobi API interface requires six steps: 1. Register a Huobi account and select "Global Station"; 2. Complete real-name authentication (L1/L2/L3); 3. Log in and enter the API management page; 4. Create an API key, fill in basic information and select permissions; 5. Generate and save Access Key and Secret Key; 6. Integrate API to the application, pay attention to security matters and change the key regularly.

From the early stages to the present, BNB has shown significant growth. Although its value continues to rise, people have asked what heights BNB can reach. This guide will explore factors that affect the price of Binance Coin. We will discuss its recent performance and make predictions for the next few years. Binance Coin Trend Prediction: How high will BNB rise? What is BNB? BNB is a cryptocurrency of Binance Exchange (official registration) (official download), and Binance is the world's leading cryptocurrency trading platform. It debuted on Ethereum as an ERC-20 token in 2017 and moved to Binance Chain in 2019. Initially, BNB was designed for Binance

Eric Semler, chairman of SemlerScientific ($SMLR), has become a representative of a significant change in the company's fiscal strategy. EricSemler is known for its open and frank discussions, and recently delivered a speech in the Strategic World 2025 organized by MicroStrategy ($MSTR). In his speech, Semler announced that SMLR became the second US public company to adopt the Bitcoin standard. This move has attracted widespread attention from the financial and cryptocurrency community. As interest in digital assets continues to increase, so does discussions about their role in fiscal reserves. Semler leads SMLR on this road and announces this cancellation in recent X posts

The AltCoin seasonal index measures performance against Bitcoin’s top altcoins in 90 days. CryptoRover shares two different charts on X, revealing some compelling trend shifts. The first chart is the focus of recent hot discussion - Altcoin season. It shows the Altcoin Seasonal Index, which measures how top altcoins perform relative to Bitcoin over 90 days. This specific data comes from blockchaincenter.net, measuring the top 50 best-performing altcoins, excluding any stablecoins or asset-backed tokens. Regarding the AltCoin Seasonal Index, if the top 50 Altcoin perform better than Bitcoin in the past 90 days, it will be

The Wall Street Journal reported that the United States will reduce the "reciprocal" tariffs on Chinese goods from the previous level of as high as 125% to 10%; at the same time, China also agreed to reduce tariffs on US goods from 125% to 10%. However, the report also pointed out that the 20% tariff and other specific measures imposed by the United States on Chinese goods on issues related to fentanyl will continue to be retained, so it can be seen as some core disputed goods. The two sides agreed to lower the current 145% tariff to 30% level. In addition, the United States and China have also stated that they will establish a mechanism and platform to continue discussions on economic and trade relations. Bitcoin technology

May 19 will become an important day for the XRP market, as an official press conference will be held on this day. This move reflects the growing enthusiasm of major financial platforms for XRP adoption. CME Group will officially launch XRP Futures on May 19, marking an important milestone for institutional investors in the development of the XRP market. The release date was officially announced by FuturesExchange, highlighting key progress in the XRP market. This action is carried out in the context of XRP adoption by major financial platforms. CME had confirmed that it would increase XRP futures a few weeks ago. This confirmation comes after CME's recent launch of SolanaFutures, showing the exchange expanding its products to Bitcoin and Ethereum

Recently, JD.com plans to launch a digital currency called "JDCCoin" in Hong Kong, commonly known as Hong Kong stablecoin. Regarding this new thing, I would like to ask on behalf of my classmates why Brother Dong did this? What impact does this have on ordinary people? What kind of changes will JD.com issue Hong Kong stablecoin? What impact will it have on you? Stablecoins are themselves a special digital currency. Evolving to this day, they are generally pegged to fiat currencies, such as the US dollar and Hong Kong dollar. With this guarantee, its value will not rise and fall like Bitcoin, but will remain relatively stable, so it is called "stable coin".

To access the official entrance of Binance Exchange, you need to open a browser. To register an account, you need to click the registration button, fill in the information, verify the email address and complete KYC verification. After logging in, you can choose a transaction pair and place an order. Deposit and withdrawal must be operated through the wallet menu. To ensure the security of the account, you must use a strong password and enable 2FA.
