eosio check account exist
To check if an account exists in EOSIO using C++, you can follow these steps:
Step 1: Import the required libraries Include the necessary C++ libraries:
#include <eosio/eosio.hpp>
#include <eosio/name.hpp>
Step 2: Define the contract class
Create a contract class that inherits from eosio::contract
:
class [[eosio::contract]] account_checker : public eosio::contract {
public:
using contract::contract;
Step 3: Define the check_account function
Inside the contract class, define a function called check_account
that takes an account name as an argument:
[[eosio::action]]
void check_account(eosio::name account) {
// code to check if the account exists
}
Step 4: Implement the check_account function
In the check_account
function, you can use the eosio::name
class to check if the account exists:
eosio::name account_name(account);
bool account_exists = account_name != eosio::name{};
Step 5: Return the result
You can return the result of the account existence check using eosio::check
:
eosio::check(account_exists, "Account does not exist");
Step 6: Close the contract class Close the contract class definition:
};
Step 7: Declare the contract
Declare the contract using the EOSIO_DISPATCH
macro:
EOSIO_DISPATCH(account_checker, (check_account))
That's it! You now have a C++ program to check if an account exists in EOSIO.