DApp(APLink) - Scatter Agreement

Scatter acquired method


  • getIdentity - acquire identity(login)

  • forgetIdentity - forget identity(logout)

  • authenticate - prove identity ownership

  • SuggestNetwork - This is a help method for requesting the addition of an EOS network that the website is currently using.

  • amax - used to obtain amaxjs using Scatter as the signProvider

  • requireVersion - The minimum specific version required for Scatter.

Acquire Scatter


Only with the scanner object can we operate the scanner.

If non page initialization requires the use of scatter, such as button click event calls, it is possible to directly obtain all window.scatter.

Note: The installation of scatter requires the initialization of the scatter plugin to be completed before the document. After completion, document.dispatchEvent(new CustomEvent("scatterLoaded"));

document.addEventListener("scatterLoaded", scatterExtension => {
    // Scatter will now be available from the window scope.
    // At this stage the connection to Scatter from the application is 
    // already encrypted. 
    const scatter = window.scatter;

    // It is good practice to take this off the window once you have 
    // a reference to it.
    window.scatter = null;

    // If you want to require a specific version of Scatter
    scatter.requireVersion(3.0);

    //...
})

Acquire Identity (login)

A pop-up box will appear for you to choose an identity. If logged in, there is no need to call getIdentity again. If called again, an error will be reported. You cannot log in again unless you call foregetIdentity to log out.

// You can require certain fields
scatter.getIdentity().then(identity => {
    //...
}).catch(error => {
    //...
});

Of course, it is also possible to obtain the identity directly from scatter.identity, but this must be obtained after identity selection.

identityinformation is as follows:

{
    "hash": "8ed9aaf4d0ec98b510fcde1616d63c198ac5b40fa5588e1a1748f13b80f5bc32",
    "publicKey": "AM6cAE3pnY7peSdzv1DPdj15dHeoiu9hmwm41JzCe9sHmYZnrdCp",
    "name": "RandomRobin6658351",
    "kyc": false,
    "accounts": [
        {
            "name": "mk",
            "authority": "active",
            "blockchain": "amax"
        }
    ]
}

Generally, only the information in accounts is used, and other information is temporarily useless (reserved for other purposes).

Forget identity (logout)

Once calling forgetIdentityscatter.identitywill be removed.

scatter.forgetIdentity().then(() => {
    //...
});

Recommend network for users


If you are not using a universal network, you can suggest that users add the network to their Scatter. It is equivalent to the user adding a network. If you are not using a universal network, you can suggest that users add the network to their Scatter. It is equivalent to the user adding a network.

scatter.suggestNetwork(network);

Random signature


You can request the Scatter to sign any type of data you wish. If you need to sign the sha256 hash, be sure to set isHash to true as it uses different signature methods. Otherwise, always make it false.

scatter.getArbitrarySignature(
    publicKey, 
    data, 
    whatfor = "Login Authentication", 
    isHash = false
)

Instantiate an AMAX object


Return an AMAX proxy object that allows for all operations on the chain.

import Amax from "@amax/amaxjs";
const client = scatter.amax(
    network,
    Amax,
    {
        ...options,
        authorization: [`${account.name}@${account.authority}`],
    },
    network.protocol,
);

Last updated