Skip to content

Instantly share code, notes, and snippets.

@raza-basit
Last active August 29, 2019 06:26
Show Gist options
  • Save raza-basit/3dce967877b1902cfb3ac5e8797d634a to your computer and use it in GitHub Desktop.
Save raza-basit/3dce967877b1902cfb3ac5e8797d634a to your computer and use it in GitHub Desktop.
// yarn add eosjs or npm install eosjs
const { Api, JsonRpc, RpcError } = require('eosjs');
const { JsSignatureProvider } = require('eosjs/dist/eosjs-jssig'); // development only
const fetch = require('node-fetch'); // node only; not needed in browsers
const { TextEncoder, TextDecoder } = require('util'); // node only; native TextEncoder/Decoder
const { TextEncoder, TextDecoder } = require('text-encoding');
const defaultPrivateKey = "<private_key_of_existing_eos_account_name>";
const signatureProvider = new JsSignatureProvider([defaultPrivateKey]);
const rpc = new JsonRpc('<eos_rpc_endpoint>', { fetch }); // http://localhost:8080
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
const action = {
"code" : "eosio",
"action" : "newaccount",
"args" : {
"creator" : "<existing_eos_account_name>",
"name" : "<new_account_name>",
"owner" : {
"accounts" : [ ],
"keys" : [ {
"key" : "<public_key_for_owner_permission>",
"weight" : 1
} ],
"threshold" : 1,
"waits" : [ ]
},
"active" : {
"accounts" : [ ],
"keys" : [ {
"key" : "<public_key_for_active_permission>",
"weight" : 1
} ],
"threshold" : 1,
"waits" : [ ]
}
}
}
(async () => {
const result = await api.transact({
actions: [action]
}, {
blocksBehind: 3,
expireSeconds: 30,
});
console.dir(result);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment