getPublicKey

Return the public key of the Account that is currently connected to the dApp.

Input Arguments

None

Success Response

ParameterDescription

address: string

Address of the connected account

publicKey: string

Public key of the connected account

Error Response

ParameterDescription

type: string

The type of error which has occured

description: string

A description of the error which has occured

data: string

Any raw data associated with the error

Example

Request

neoline.getPublicKey()
.then(publicKeyData => {
    const {
        address,
        publicKey
    } = publicKeyData;

    console.log('Account address: ' + address);
    console.log('Account public key: ' + publicKey);
})
.catch((error) => {
    const {type, description, data} = error;
    switch(type) {
        case 'NO_PROVIDER':
            console.log('No provider available.');
            break;
        case 'CONNECTION_DENIED':
            console.log('The user rejected the request to connect with your dApp');
            break;
        default:
            // Not an expected error object.  Just write the error to the console.
            console.error(error);
            break;
    }
});

Response

{
    address: 'NaUjKgf5vMuFt7Ffgfffcpc41uH3adx1jq',
    publicKey: '6PYKGV4numxfoswwCedXzhb1oNCC8W4tEdfFPdtWtFa8WidpzYfeJkd2To'
}

最后更新于