Another option that don't require your FullAccessKey
is creating sub-accounts via a contract deployed to your account.
If you are using rust and near-sdk-rs
you should call the fuction create_account
. This is an example from the docs about how to use it:
Promise::new("bob_near".to_string())
.create_account()
.transfer(1000)
.add_full_access_key(env::signer_account_pk());
This is the code of a contract that handles sub-account creation:
use borsh::{BorshDeserialize, BorshSerialize};
use near_sdk::{env, near_bindgen, AccountId, Balance, Promise};
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
#[near_bindgen]
#[derive(Default, BorshDeserialize, BorshSerialize)]
pub struct Registry {}
#[near_bindgen]
impl Registry {
#[init]
pub fn init() -> Self {}
#[payable]
pub fn create_account(&mut self, name: AccountId, balance: Balance) -> Promise {
let target = format!("{}.{}", name, env::current_account_id());
// Here add some rules in case you don't want everyone
// to claim any unclaimed sub-account.
Promise::new(target)
.create_account()
.transfer(balance)
.add_full_access_key(env::signer_account_pk())
}
}
To create any sub-account any user can call the function create_account
function in the contract passing the name of the sub-account (only the prefix before the dot) and the balance that will be used to initialize the account.
This will work even if the main account doesn't have any FullAccessKey
anymore.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…