创建Ripple山寨币

下文是在Linux下写的,Linux下没有安装中文输入法,所以全是英文,不过没有复杂单词,阅读难度不大。这篇文章是这几天摸索创建山寨ripple币时的笔记,记录了如何创建新的Ripple创世账本,如何用ripple-api来进行交易。
create fake-ripple and test it edit ripple sourcecode to create new Genesis Ledger 1. edit Ledger to create new Genesis Ledger
replace “masterpassphrase” with what you like.
generateSeed("masterpassphrase");

2. log out AccountId and secret of new Genesis Ledger
auto const seed = generateSeed("masterpassphrase"); auto genesisKeyPair = generateKeyPair(KeyType::secp256k1, seed); PublicKey genesisPublicKey = genesisKeyPair.first; SecretKey genesisSecretKey = genesisKeyPair.second; auto const humanSecretKey = toBase58(seed); static auto const id = calcAccountID(genesisPublicKey); auto const humanId = toBase58(id); JLOG(m_journal.warn()) << " Ledger printPublicKeyAndSecretKey:" << " Ledger PublicKey:" << genesisPublicKey << " Ledger AccountId:" << id << " Ledger HumanAccountId" << humanId << " Ledger SecretKey:" << genesisSecretKey.to_string() << " Ledger HumanSecretKey:" << humanSecretKey;

run ripple server and use ripple-api to exchange 1. run ripple in stand-alone mode
sudo ./rippled -a --start --conf=/home/along/CLionProjects/ripple-test/cfg/rippled-example.cfg
2. use ripple-api to payment
'use strict'; const RippleAPI = require('ripple-lib').RippleAPI; // require('ripple-lib')// const address = 'INSERT ADDRESS HERE'; // const secret = 'INSERT SECRET HERE'; const gesisAccount = { secret: "snoPBrXtMeMyMHUVTgbuqAfg1SUTb", address: "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh" }; const myAccount = { secret: "ssEz4WN91XDhEXCYMS2GXhfCd3Ji5", address: "r3DoZn2koSVyewVzctLnG2XJSe9nixyGfP" }; const api = new RippleAPI({ server: 'ws://localhost:6006' }); // const instructions = { maxLedgerVersionOffset: 5 }; const payment = { source: { address: gesisAccount.address, maxAmount: { value: '10000', currency: 'XRP' } }, destination: { address: myAccount.address, amount: { value: '10000', currency: 'XRP' } } }; function quit(message) { console.log(message); process.exit(0); }function fail(message) { console.error(message); process.exit(1); }api.connect().then(() => { console.log('Connected...'); return api.preparePayment(gesisAccount.address, payment) .then(prepared => { console.log('Payment transaction prepared...'); console.log(prepared); const { signedTransaction } = api.sign(prepared.txJSON, gesisAccount.secret); console.log('Payment transaction signed...'); console.log(signedTransaction); api.submit(signedTransaction).then(quit, fail); }); }).catch(fail);

3. advance ripple ledger
【创建Ripple山寨币】./rippled ledger_accept --conf=/home/along/CLionProjects/ripple-test/cfg/rippled-example.cfg
4. get account info
'use strict'; const gesisAccount = { secret: "snoPBrXtMeMyMHUVTgbuqAfg1SUTb", address: "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh" }; const myAccount = { secret: "ssEz4WN91XDhEXCYMS2GXhfCd3Ji5", address: "r3DoZn2koSVyewVzctLnG2XJSe9nixyGfP" }; const RippleAPI = require('ripple-lib').RippleAPI; const api = new RippleAPI({ //server: 'wss://s1.ripple.com' // Public rippled server server: "ws://localhost:6006" }); api.connect().then(() => { /* begin custom code ------------------------------------ */ console.log('getting account info for', myAccount.address); return api.getAccountInfo(myAccount.address); }).then(info => { console.log(info); console.log('getAccountInfo done'); /* end custom code -------------------------------------- */ }).then(() => { return api.disconnect(); }).then(() => { console.log('done and disconnected.'); }).catch(console.error);

我的博客即将搬运同步至腾讯云+社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=27u0vgwevihwc

    推荐阅读