EOS,可以理解为Enterprise Operation System,即为商用分布式应用设计的一款区块链操作系统。EOS是引入的一种新的区块链架构,旨在实现分布式应用的性能扩展。注意,它并不是像比特币和以太坊那样的货币,而是基于EOS软件项目之上发布的代币,被称为区块链3.0。
下面教程就是用JavaScript去生成一个简易的EOS钱包。
开发环境
依赖库安装
npm install bip39 npm install eosjs-ecc npm install eosjs
引入依赖库
import bip39 from 'bip39'; import eosEcc from 'eosjs-ecc';
随机生成钱包
eosEcc.randomKey().then(privateKey => { console.log('Private Key:\t', privateKey) let privateKey = privateKey; let publicKey = eosEcc.privateToPublic(privateKey); });
通过助记词生成私钥、公钥
let privateKey = eosEcc.seedPrivate(mnemonic); let publicKey = eosEcc.privateToPublic(privateKey);
注册EOS账户
var Eos = require('eosjs') var eosConfig = { keyProvider: ['私钥'], // 配置私钥字符串 httpEndpoint: 'http://51.15.224.168:8888', //DEV开发链url与端口 //httpEndpoint: 'https://nodes.get-scatter.com', //主网 chainId: "038f4b0fc8ff18a4f0842a8f0564611f6e96e8535901dd45e43ac8691a1c4dca", // 通过cleos get info可以获取chainId //chainId: "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906", //主网 broadcast: true, } var eos = Eos(eosConfig) var creatoraccount = "accounthr123"; //主账号 var newaccount = "sdrghiochaiq"; //新账号 var newaccount_pubkey = pubkey; //新账号的公钥 //构建transaction对象 eos.transaction(tr => { //新建账号 tr.newaccount({ creator: creatoraccount, name: newaccount, owner: newaccount_pubkey, active: newaccount_pubkey }) //为新账号充值RAM tr.buyrambytes({ payer: creatoraccount, receiver: newaccount, bytes: 3072 }) //为新账号抵押CPU和NET资源 tr.delegatebw({ from: creatoraccount, receiver: newaccount, stake_net_quantity: '1.0000 EOS', stake_cpu_quantity: '1.0000 EOS', transfer: 0 }) }).then(r => { console.log(r); }).catch(e => { console.log(e) });
还没有评论,来说两句吧...