How to use the tronweb.isAddress function in tronweb

To help you get started, we’ve selected a few tronweb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TronLink / tronlink-extension / packages / backgroundScript / services / WalletService / index.js View on Github external
async importAccount({ privateKey, name }) {
        // 埋点

        logger.info(`Importing account '${ name }' from popup`);

        const account = new Account(
            privateKey.match(/^T/) && TronWeb.isAddress(privateKey) ? ACCOUNT_TYPE.LEDGER : ACCOUNT_TYPE.PRIVATE_KEY,
            privateKey
        );

        const {
            address
        } = account;

        account.name = name;
        if (Object.keys(this.accounts).length === 0) {
            this.setCache();
        }
        this.accounts[address] = account;
        StorageService.saveAccount(account);

        this.emit('setAccounts', this.getAccounts());
        this.selectAccount(address);
github TronLink / tronlink-extension / packages / backgroundScript / services / WalletService / Account.js View on Github external
_importPrivateKey(privateKey) {
        try {
            if (privateKey.match(/^T/) && TronWeb.isAddress(privateKey)) {
                this.privateKey = null;
                this.address = privateKey;
            } else {
                this.privateKey = privateKey;
                this.address = TronWeb.address.fromPrivateKey(privateKey);
            }
        } catch (ex) { // eslint-disable-line
            throw new Error('INVALID_PRIVATE_KEY');
        }
    }
github TronLink / tronlink-extension / packages / popup / src / pages / TokensPage / index.js View on Github external
onChange(address) {
        address = address.trim();

        const { smart } = this.props.tokens;
        const error = Object.keys(smart).includes(address) ? 'ERRORS.TOKEN_ADDED' : false;

        let isValid = !error && address.length === 34;

        try {
            isValid = isValid && TronWeb.isAddress(address);
        } catch {}

        this.setState({
            address,
            isValid,
            error
        });
    }
github TronLink / tronlink-extension / packages / popup / src / controllers / SendController.js View on Github external
async onRecipientChange(address) {
        const { selectedAddress } = this.state;
        const { chains } = this.props;
        const recipient = {
            value: address,
            valid: VALIDATION_STATE.NONE
        };

        if(!address.length)
            return this.setState({recipient:{value: '', valid: false, error: ''}});

        if(!TronWeb.isAddress(address)) {
            recipient.valid = false;
            recipient.error = 'EXCEPTION.SEND.ADDRESS_FORMAT_ERROR';
        } else {
            const account = await PopupAPI.getAccountInfo(address);
            if(!account[chains.selected === '_'? 'mainchain' : 'sidechain' ].address) {
                recipient.isActivated = false;
                recipient.valid = true;
                recipient.error = 'EXCEPTION.SEND.ADDRESS_UNACTIVATED_ERROR';
            } else if(address === selectedAddress) {
                recipient.isActivated = true;
                recipient.valid = false;
                recipient.error = 'EXCEPTION.SEND.ADDRESS_SAME_ERROR';
            } else {
                recipient.isActivated = true;
                recipient.valid = true;
                recipient.error = '';
github TronLink / tronlink-extension / packages / popup / src / controllers / AddTokenController.js View on Github external
<input type="text"> {
                                const value = e.target.value;
                                this.state.address.value = value;
                                this.state.address.valid = TronWeb.isAddress(value);
                                this.setState({ address: this.state.address });
                            }} placeholder={formatMessage({ id: 'MENU.ADD_TRC20_TOKEN.INPUT_PLACE_HOLDER' })} /&gt;
github TronLink / tronlink-extension / packages / popup / src / pages / SendPage / index.js View on Github external
onRecipientChange(address) {
        address = address.trim();

        const recipient = {
            value: address,
            valid: VALIDATION_STATE.NONE
        };

        if(!address.length)
            return this.setState({ recipient });

        if(!TronWeb.isAddress(address))
            recipient.valid = VALIDATION_STATE.INVALID;
        else recipient.valid = VALIDATION_STATE.VALID;

        this.setState({
            recipient
        });
    }

tronweb

JavaScript SDK that encapsulates the TRON HTTP API

MIT
Latest version published 2 months ago

Package Health Score

84 / 100
Full package analysis