eos 新建账号

2022-6-6

已经建好uudcatcatcat账号,并有足够的cpu time 和 足够eos,创建shengchatest账号


// const bip39 = require("bip39");
// const hdkey = require("hdkey");
const eosEcc = require("eosjs-ecc");

const mnemonic = "mnemonic";
let privateKey = eosEcc.seedPrivate(mnemonic);
let publicKey = eosEcc.privateToPublic(privateKey);

// const mnemonic = 'mnemonic'

// const seed = bip39.mnemonicToSeedSync(mnemonic)

// const root = hdkey.fromMasterSeed(seed)

// const path = "m/44'/194'/0'/0/0"
// const node = root.derive(path)

// console.log({node});

//
// let newaccount_privateKey = ''
// let newaccount_pubkey = ''
// eosEcc.randomKey().then(pr => {
//     newaccount_privateKey = pr
//     newaccount_pubkey = eosEcc.privateToPublic(pr)
// })

const newaccount_pubkey = 'EOS5vTVAWRhJzHsCyjAoGcWC2tjzfUz5HTkNa7zDA6SFRiMmKvn6m'

const fetch = require('node-fetch');
const { Api, JsonRpc, RpcError } = require("eosjs");
const { JsSignatureProvider } = require("eosjs/dist/eosjs-jssig");

const signatureProvider = new JsSignatureProvider([privateKey]);
const rpc = new JsonRpc("https://jungle3.cryptolions.io:443", { fetch, });

const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder(), });

api.transact({
    actions: [
        {
            // 这个account是指合约名
            account: "eosio",
            name: "newaccount",
            authorization: [
                {
                    actor: "uudcatcatcat",
                    permission: "active",
                },
            ],
            data: {
                creator: "uudcatcatcat",
                // 这里的name指的是新用户的名字,在内部测试时候用的是name这个字段。
                name: "shengchatest",
                owner: {
                    threshold: 1,
                    keys: [
                        {
                            key: newaccount_pubkey,
                            weight: 1,
                        },
                    ],
                    accounts: [],
                    waits: [],
                },
                active: {
                    threshold: 1,
                    keys: [
                        {
                            key: newaccount_pubkey,
                            weight: 1,
                        },
                    ],
                    accounts: [],
                    waits: [],
                },
            },
        },
        {
            account: 'eosio',
            name: 'buyrambytes',
            authorization: [{
                actor: 'uudcatcatcat',
                permission: 'active',
            }],
            data: {
                payer: 'uudcatcatcat',
                receiver: 'shengchatest',
                bytes: 8192,
            },
        },
        {
            account: 'eosio',
            name: 'delegatebw',
            authorization: [{
                actor: 'uudcatcatcat',
                permission: 'active',
            }],
            data: {
                from: 'uudcatcatcat',
                receiver: 'shengchatest',
                stake_net_quantity: '1.0000 EOS',
                stake_cpu_quantity: '1.0000 EOS',
                transfer: false,
            }
        }
    ],
}, {
    blocksBehind: 3,
    expireSeconds: 30,
}).then(res => {
    console.log({res});
}).catch(err => {
    console.log({err});
})


遇到问题了? 可以直接联系我

评论区