📅  最后修改于: 2023-12-03 15:14:08.227000             🧑  作者: Mango
Checksum addresses are a type of wallet addresses that are designed to reduce the risk of errors during transmission or typing of the address. The idea behind this is to include a checksum in the address itself, which can be used to authenticate the address and detect any typos or errors.
For example, Ethereum uses a checksum address format that includes both uppercase and lowercase characters. This makes it easier to identify if an address is valid or not, which reduces the chance of sending crypto assets to a wrong address.
A checksum address is created by taking the first 20 bytes of the SHA3-256 hash of the lowercase version of the address. This checksum is then appended to the end of the address, resulting in a longer address that includes both uppercase and lowercase characters.
When sending cryptocurrencies to a checksum address, the recipient's wallet software will check if the address is valid by checking the checksum. If the checksum matches the address, the transaction will proceed; otherwise, it will be rejected.
Checksum addresses help to prevent the loss of crypto assets due to human errors. By including a checksum in the address, the risks of sending funds to an incorrect address are reduced significantly. Errors like missing or incorrect characters are more easily detected, which means fewer lost assets for the user.
In Ethereum, you can generate a checksum address by converting the address to lowercase, generating the SHA3-256 hash, and then converting the hash to hex. The first 20 bytes of this hashed string are then appended to the original lowercase address, resulting in a checksum address.
Here's an example in Python:
from ethereum.utils import sha3
def toChecksumAddress(address):
address = address.lower()
addressHash = sha3(address.encode('utf-8')).hexdigest()
checksumAddress = '0x'
for i in range(len(address)):
if int(addressHash[i], 16) > 7:
checksumAddress += address[i].upper()
else:
checksumAddress += address[i]
return checksumAddress
In summary, checksum addresses are an essential tool for ensuring the safety and security of user's crypto assets. By using a checksum in the address, we reduce the risk of errors and greatly improve the user experience.