Created
March 14, 2020 09:54
-
-
Save cc32d9/ee77af5d613f87ff0cba61c7af3cfe44 to your computer and use it in GitHub Desktop.
Example for building a newaccount transaction in eosjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// here MYACC is the account sending the transaction | |
// NEWACC is the name of account being created | |
await (async () => { | |
try { | |
console.info('Creating account'); | |
const result = await api.transact( | |
{ | |
actions: | |
[ | |
{ | |
account: 'eosio', | |
name: 'newaccount', | |
authorization: [{ | |
actor: MYACC, | |
permission: 'active'} ], | |
data: { | |
creator: MYACC, | |
name: NEWACC, | |
owner: { | |
threshold: 1, | |
keys: [{ key: key.public, weight: 1}], | |
accounts: [], | |
waits: [] | |
}, | |
active: { | |
threshold: 1, | |
keys: [{ key: key.public, weight: 1}], | |
accounts: [], | |
waits: [], | |
}, | |
}, | |
}, | |
{ | |
account: 'eosio', | |
name: 'buyrambytes', | |
authorization: [{actor: MYACC, permission: 'active'}], | |
data: { | |
payer: MYACC, | |
receiver: NEWACC, | |
bytes: 8192, | |
}, | |
}, | |
{ | |
account: 'eosio', | |
name: 'delegatebw', | |
authorization: [{actor: MYACC, permission: 'active'}], | |
data: { | |
from: MYACC, | |
receiver: NEWACC, | |
stake_net_quantity: '1.0000 TLOS', | |
stake_cpu_quantity: '1.0000 TLOS', | |
transfer: false | |
} | |
} | |
] | |
}, | |
{ | |
blocksBehind: 3, | |
expireSeconds: 30 | |
} | |
); | |
console.info('transaction_id is : ', result.transaction_id); | |
} catch (e) { | |
console.error('ERROR: ' + e); | |
} | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment