Creating a Testnet account

After installing the local tooling provided by Near you may create a test net account:

# Replace <your-account-id.testnet> with a custom name
near create-account <your-account-id.testnet> --useFaucet

or if you want to specify custom parameters:

near account create-account sponsor-by-faucet-service <your-account-id.testnet> autogenerate-new-keypair save-to-keychain network-config testnet create

In both cases, if the account id is available, you'll get an output like this:

Your transaction:
signer_id:    testnet
actions:
   -- create account:      vfp.testnet
   -- add access key:     
                   public key:   ed25519:2nh8uWoxsHDj9hzUKfkabtL7YDSTBNPSTDPsaz8ELQoX
                   permission:   FullAccess

▹▹▸▹▹ Creating a new account ...  
▹▹▸▹▹  ↳  Receiving request via faucet service https://helper.nearprotocol.com/account                                
New account <vfp.testnet> created successfully.
The data for the access key is saved in the keychain

Transaction ID: GLDRf3R17GJmpfpaiioX4WXMS2FkV3jxSUVYQZ6wdQtx
To see the transaction in the transaction explorer, please open this url in your browser:
https://explorer.testnet.near.org/transactions/GLDRf3R17GJmpfpaiioX4WXMS2FkV3jxSUVYQZ6wdQtx


Here is your console command if you need to script it or re-run:
    near account create-account sponsor-by-faucet-service vfp.testnet autogenerate-new-keypair save-to-keychain network-config testnet create

To understand what a custom_name is, just keep on reading.

Accounts

  • Account ID. It is a unique identifier associated with each account on the NEAR blockchain. Account IDs are human-readable and are typically represented as strings. For instance, alice.near or my_dapp.near could be valid account IDs. Account IDs act as the addresses to which funds can be sent and provide access to the associated ac- count’s data and smart contract functionality.

  • Implicit accounts. are created automatically as part of a transaction. When a transaction is sent from a particular account ID that does not exist, NEAR automatically creates an implicit account with that ID. Implicit accounts are useful for one-time interactions or temporary data storage within a transaction.

#![allow(unused)]
fn main() {
// Create an implicit account in a transaction
#[near_bindgen]
pub fn create_implicit_account(&mut self, account_id: String) {
    let account_id: ValidAccountId = account_id.try_into().unwrap();
    env::log(format!("Creating implicit account: {}",   account_id).as_bytes());
    // Perform actions with the implicit account
    // ...
}
}
  • Named accounts

Accounts with persistent state and private keys. They can receive funds, store data, and interact with other smart contracts. Named accounts provide a more permanent identity for users or dApps within the NEAR ecosystem. Developers can create and manage named accounts programmatically using NEAR’s SDKs.

Account creation and contract deployment

#![allow(unused)]
fn main() {
const NEAR_RPC_URL: &str = "https://rpc.mainnet.near.org";// Connect to the NEAR network
let near = near_sdk::connect::connect(near_sdk::Config {
	network_id: "mainnet".to_string(),
	node_url: NEAR_RPC_URL.to_string(),
});
// Create a new account using async/await and Promises API
async fn create_and_deploy() {
	let new_account = near.create_account("new_account").await.unwrap();
	// Load contract code
	let contract_code = include_bytes!("path/to/contract.wasm");
	// Deploy a contract to the new account using Promises API
	new_account.deploy_contract(contract_code).await.unwrap();
}
// You can call `create_and_deploy` function in an async context
}