創(chuàng)建Ripple山寨幣

下文是在Linux下寫的,Linux下沒有安裝中文輸入法,所以全是英文,不過沒有復(fù)雜單詞,閱讀難度不大。這篇文章是這幾天摸索創(chuàng)建山寨ripple幣時的筆記,記錄了如何創(chuàng)建新的Ripple創(chuàng)世賬本,如何用ripple-api來進(jìn)行交易。

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

./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);
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容