getNetworks

Returns the networks the wallet provider has available to connect to, along with the default network the wallet is currently set to.

Input Arguments

None

Success Response

ParameterDescription

networks: string[]

Array of network names the wallet provider has available for the dapp developer to connect to

ChainId the wallet is currently set to

defaultNetwork: string

Network the wallet is currently set to

Chain IDs Type

These are the IDs of the Neo chain supported by NeoLine.

chainIdDescription

1

ChainId 1 is the Neo2 MainNet

2

ChainId 2 is the Neo2 TestNet

3

ChainId 3 is the N3 MainNet

6

ChainId 6 is the N3 TestNet (Currently only N3 TestNet)

0

ChainId 0 is the N3 Private Network

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.getNetworks()
.then(result => {
    const {
        chainId,
        networks,
        defaultNetwork
    } = result;

    console.log('chainId: ' + chainId);
    // eg. 6

    console.log('Networks: ' + networks);
    // eg. ["MainNet", "TestNet", "N3TestNet"]

    console.log('Default network: ' + defaultNetwork);
    // eg. "N3TestNet"
})
.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;
        case 'CHAIN_NOT_MATCH':
            console.log('The currently opened chain does not match the type of the call chain, please switch the chain.');
            break;
        default:
            // Not an expected error object.  Just write the error to the console.
            console.error(error);
            break;
    }
});

Response

{
    chainId: 6,
    networks: ["MainNet", "TestNet", "N3TestNet"],
    defaultNetwork: "N3TestNet"
}

最后更新于