I am trying to find a way to create a new account in EOSIO without using CLEOS.
Is there any way to create a new account? Any example for this?
My Answer:
Yes, you can create a new account in EOSIO using the EOSIO API. Here is an example of how you can do this using PHP:
php
$api_url = 'http://localhost:8888/v1/chain';
$wallet_url = 'http://localhost:8888/v1/wallet';
// Create a new wallet
$wallet_create = json_decode(file_get_contents($wallet_url . '/create'), true);
$wallet_name = $wallet_create['wallet_name'];
// Import private key
$private_key = 'YOUR_PRIVATE_KEY';
$import_key = json_decode(file_get_contents($wallet_url . '/import_key'), true);
// Create new account
$account_name = 'NEW_ACCOUNT_NAME';
$creator_account = 'CREATOR_ACCOUNT_NAME';
$creator_key = 'CREATOR_PRIVATE_KEY';
$create_account_data = array(
'creator' => $creator_account,
'name' => $account_name,
'owner' => array(
'threshold' => 1,
'keys' => array(
array(
'key' => $import_key['private_key'],
'weight' => 1
)
),
'accounts' => array(),
'waits' => array()
),
'active' => array(
'threshold' => 1,
'keys' => array(
array(
'key' => $import_key['private_key'],
'weight' => 1
)
),
'accounts' => array(),
'waits' => array()
)
);
$create_account_response = json_decode(file_get_contents($api_url . '/push_transaction', false, stream_context_create(array(
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/json',
'content' => json_encode(array(
'compression' => 'none',
'transaction' => array(
'actions' => array(
array(
'account' => 'eosio',
'name' => 'newaccount',
'authorization' => array(
array(
'actor' => $creator_account,
'permission' => 'active'
)
),
'data' => $create_account_data
)
)
)
))
)
)));
print_r($create_account_response);
?>
Make sure to replace `YOUR_PRIVATE_KEY`, `NEW_ACCOUNT_NAME`, `CREATOR_ACCOUNT_NAME`, and `CREATOR_PRIVATE_KEY` with your actual private key, new account name, creator account name, and creator private key respectively.
This code will create a new account in EOSIO using the specified creator account and private key.
Rate this post
4 of 5 based on 3529 votesComments