-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Any Idea how to generate address of nuls coin in main net in node js? #34
Comments
Please don't spam your question(s) across multiple repositories. You will need to use REST to send commands to the node, and it can be done like: post(`${nodeAddress}/account`, {count: 1, password: "${addressPassword}"}); |
As I replied in nuls.community (https://nuls.community/d/77-api-to-generate-address-in-terminal/8) You'll need to npm install some packages, but I leave that to you :): #!/usr/bin/node
const RIPEMD160 = require('ripemd160')
const secp256k1 = require('secp256k1')
const shajs = require('sha.js')
const getRandomValues = require('get-random-values')
const bs58 = require('bs58')
function getxor (body) {
let xor = 0
for (var i = 0; i < body.length; i++) {
xor = xor ^ body[i]
}
return xor
}
function private_key_to_public_key (prv) {
return secp256k1.publicKeyCreate(prv)
}
function public_key_to_hash (pub, { chain_id = 8964, address_type = 1 } = {}) {
let sha = new shajs.sha256().update(pub).digest()
let pubkeyHash = new RIPEMD160().update(sha).digest()
let output = Buffer.allocUnsafe(3)
output.writeInt16LE(chain_id, 0)
output.writeInt8(address_type, 2)
return Buffer.concat([output, pubkeyHash]) //.toString('hex')
}
function address_from_hash (hash) {
//const bytes = Buffer.from(hash, 'hex')
const address = bs58.encode(Buffer.concat([hash, new Buffer([getxor(hash)])]))
return address
}
function generate() {
let randArr = new Uint8Array(32) //create a typed array of 32 bytes (256 bits)
let privKey
do {
getRandomValues(randArr)
privKey = Buffer.from(randArr)
} while (!secp256k1.privateKeyVerify(privKey))
return privKey
}
var numberOfWallets = 5;
for (var i = 0; i < numberOfWallets; i++) {
let privateKey = generate();
let pub = private_key_to_public_key(privateKey);
let hash = public_key_to_hash(pub);
let address = address_from_hash(hash);
console.log(address,privateKey.toString('hex'));
}; |
Sorry for that but actually we are working in this coin in very urgent basis and it is a new coin.And as i was not getting any help in node js so posted here ..Thanks for your reply...... |
Thanks for the help I have successfully generated the public and private key.... |
Do you have any idea for the api for the nuls coin to get balance for mainnet....i have found this but not getting balance and utxo details... Thanks for the above code helped to generate the address.. |
@shweta037 You want get balance for your address.
|
I got the balance using:- nuls.getTxListByAddress({"address":"Nse2vPEzc2wvjKXUoRbw1JmyTDjNmpbT"},function(data){ now I need to do transaction in mainnet without using password in node.js |
No description provided.
The text was updated successfully, but these errors were encountered: