BSC Address


Since BSC is fork of ethereum. Therefore this page is alias of ethereum address page.

BSC addresses are composed of the prefix "0x", a common identifier for hexadecimal, concatenated with the rightmost 20 bytes of the Keccak-256 hash (big endian) of the ECDSA public key (the curve used is the so-called secp256k1, the same as Bitcoin)

There are 2 types of account in BSC network, externally owned account (EOA) and contract account. Remember account just simply mean an address.

Externally owned account (EOA)

  • Controlled by private key.
  • Has BNB balance state

Contract account

  • No private key, controlled by codes written in contract.
  • Has BNB balance state
  • Has associated code and state of variables declared in contract.
  • Learn more about Smart Contract.


EOA Address Generator

<?php 
use kornrunner\Keccak;
use BitWasp\Bitcoin\Key\Factory\PrivateKeyFactory;
use BitWasp\Bitcoin\Crypto\Random\Random;

include_once "../libraries/vendor/autoload.php";
include_once("html_iframe_header.php");

function toChecksumAddress($address) 
{
	
	$address = strtolower(str_replace('0x', '', $address));
	$hash = Keccak::hash(strtolower($address), 256);
	$checksumAddress = '0x';
	
	for($i=0;$i<strlen($address);$i++) {
		
		if (intval($hash{$i}, 16) > 7) {
			$checksumAddress .= strtoupper($address{$i});
		} else {
			$checksumAddress .= $address{$i};
		}
	}
	
	return $checksumAddress;
	
}

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    try {
       
        $privKeyFactory = new PrivateKeyFactory();

        if (!$_POST['input'] OR ctype_xdigit($_POST['input'])) 
        {
            if (!$_POST['input']) 
            { 
                $rbg = new Random();
                $privateKey = $privKeyFactory->generateUncompressed($rbg);
                
            } else {
                
                $privateKey = $privKeyFactory->fromHexUncompressed($_POST['input']);
            }
        } 
       
		$publicKey = $privateKey->getPublicKey();
		$publicKey = substr($publicKey->getHex(), 2);
		$madeUpEthAddress = $publicKey;
		
		$hash = Keccak::hash(hex2bin($madeUpEthAddress), 256);
		// Ethereum address has 20 bytes length. (40 hex characters long)
		// We only need the last 20 bytes as Ethereum address
		$ethAddress = toChecksumAddress('0x' . substr($hash, -40));
		
    ?>
        <div class="table-responsive">
            <table border=0 class='table'>
                <tr style='background-color:#f0f0f0'><td>Address</td><td><?php echo $ethAddress?></td></tr>
                <tr><td>Private Key Hex</td><td><?php echo $privateKey->getHex()?></td></tr>               
                <tr style='background-color:#f0f0f0'><td>Public Key Hex</td><td><?php echo $publicKey?></td></tr>
            </table>
        </div>
<?php 
    } catch (Exception $e) {
        $errmsg .= "Problem found. " . $e->getMessage();

    }
} 

if ($errmsg) {
?>
    <div class="alert alert-danger">
        <strong>Error!</strong> <?php echo $errmsg?>
    </div>
<?php
}
?>
<form action='' method='post'>
    <div class="form-group">
        <label for="input">Private Key (Hex):</label>
        <input class="form-control" type='text' name='input' id='input' value='<?php echo $_POST['input']?>'>
        <small>Put empty if you want system assign you a random private key.</small>
    </div>
   
    <input type='submit' class="btn btn-success btn-block"/>
</form>
<?php
include_once("html_iframe_footer.php");

Address Validator

Address checksum was described in EIP-55.

<?php 
use kornrunner\Keccak;

include_once "../libraries/vendor/autoload.php";
include_once("html_iframe_header.php");

class EthAddressValidator
{
	private $addressValid = false;
	private $address = "";
	
	function __construct(string $address) 
	{
		$this->address = $address;
		if ($this->isPatternMatched()) {
			if (!$this->isAllSameCaps()) {
				$this->addressValid = $this->isValidChecksum();	
			} else {
				$this->addressValid = true;
			}
        }
	}
	
    public function isValidAddress(): bool
    {	
        return $this->addressValid;
    }
	
    protected function isPatternMatched(): int
    {
        return preg_match('/^(0x)?[0-9a-f]{40}$/i', $this->address);
    }

    public function isAllSameCaps(): bool
    {
        return preg_match('/^(0x)?[0-9a-f]{40}$/', $this->address) || preg_match('/^(0x)?[0-9A-F]{40}$/', $this->address);
    }

    protected function isValidChecksum(): bool
    {
        $address = str_replace('0x', '', $this->address);
        $hash = Keccak::hash(strtolower($address), 256);

        for ($i = 0; $i < 40; $i++ ) {
            if (ctype_alpha($address{$i})) {
                // Each uppercase letter should correlate with a first bit of 1 in the hash char with the same index,
                // and each lowercase letter with a 0 bit.
                $charInt = intval($hash{$i}, 16);

                if ((ctype_upper($address{$i}) && $charInt <= 7) || (ctype_lower($address{$i}) && $charInt > 7)) {
					
                    return false;
                }
            }
        }

        return true;
    }
}

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
   
    $validator = new EthAddressValidator($_POST['address']);
	
	if ($validator->isAllSameCaps() === true) {
	?>
		<div class="alert alert-info">
			<strong>Notice!</strong> Address pattern valid but checksum cannot be verified.
		</div>
	<?php 
	} else if ($validator->isValidAddress() === true) {
?>
		<div class="alert alert-success">
			<strong>Success!</strong> Checksum validation was passed.
		</div>
<?php
	} else {
?>
		<div class="alert alert-danger">
			<strong>Error!</strong> Invalid address.
		</div>	
<?php	
	}
}
?>
<form action='' method='post'>
    <div class="form-group">
        <label for="address">Address:</label>
        <input class="form-control" type='text' name='address' id='address' value='<?php echo $_POST['address']?>'>
    </div>
   
    <input type='submit' class="btn btn-success btn-block"/>
</form>
<?php
include_once("html_iframe_footer.php");








Tutorials
About Us
Contents have been open source in GITHUB. Please give me a ⭐ if you found this helpful :)
Community
Problem? Raise me a new issue.
Support Us
Buy me a coffee. so i can spend more nights for this :)

BTCSCHOOLS would like to present you with more pratical but little theory throughout our tutorials. Pages' content are constantly keep reviewed to avoid mistakes, but we cannot warrant correctness of all contents. While using this site, you agree to accept our terms of use, cookie & privacy policy. Copyright 2019 by BTCSCHOOLS. All Rights Reserved.