web3.js
const address = "0x0089d53F703f7E0843953D48133f74cE247184c2"
let result = Web3.utils.isAddress(address)
console.log(result) // => true
web3j
社区fork为其增加了isAddress
commit
https://github.com/bcskill/web3j
package org.web3j.utils;
import org.junit.Test;
import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.web3j.utils.Account.isAddress;
public class AccountTest {
@Test
public void verifyIsAddress() {
String validLowerCaseAddress = "0x3de8c14c8e7a956f5cc4d82beff749ee65fdc358";
assertTrue(isAddress(validLowerCaseAddress));
String validChecksumAddress = "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359";
assertTrue(isAddress(validChecksumAddress));
String invalidLengthAddress = "0x3de8c14c8e7a956f5cc4d82beff749ee65bac35";
assertFalse(isAddress(invalidLengthAddress));
String invalidChecksumAddress = "0x3de8c14c8E7a956f5cc4d82beff749ee65fdc358";
assertFalse(isAddress(invalidChecksumAddress));
}
}
参考
https://piyopiyo.medium.com/how-to-check-if-ethereum-address-is-valid-or-not-ef587b6c4819
https://github.com/assafY/web3j.git
版权属于:区块链中文技术社区 / 转载原创者
本文链接:https://bcskill.com/index.php/archives/1127.html
相关技术文章仅限于相关区块链底层技术研究,禁止用于非法用途,后果自负!本站严格遵守一切相关法律政策!