type | version | package |
---|---|---|
core | zjubca-scatterjs-core | |
blockchain | zjubca-scatterjs-plugin-eosjs | |
blockchain | zjubca-scatterjs-plugin-eosjs2 |
Here's some boilerplates for you to just get starts quickly.
eosjs@16.0.9
Installation: npm i -S zjubca-scatterjs-core zjubca-scatterjs-plugin-eosjs eosjs@16.0.9
import ScatterJS from 'zjubca-scatterjs-core';
import ScatterEOS from 'zjubca-scatterjs-plugin-eosjs';
import Eos from 'eosjs';
ScatterJS.plugins( new ScatterEOS() );
const network = ScatterJS.Network.fromJson({
blockchain:'eos',
chainId:'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906',
host:'nodes.get-scatter.com',
port:443,
protocol:'https'
});
ScatterJS.connect('YourAppName', {network}).then(connected => {
if(!connected) return console.error('no scatter');
const eos = ScatterJS.eos(network, Eos);
ScatterJS.login().then(id => {
if(!id) return console.error('no identity');
const account = ScatterJS.account('eos');
const options = {authorization:[`${account.name}@${account.authority}`]};
eos.transfer(account.name, 'safetransfer', '0.0001 EOS', account.name, options).then(res => {
console.log('sent: ', res);
}).catch(err => {
console.error('error: ', err);
});
});
});
eosjs@20.0.0-beta3
Installation: npm i -S zjubca-scatterjs-core zjubca-scatterjs-plugin-eosjs2 eosjs@20.0.0-beta3
import ScatterJS from 'zjubca-scatterjs-core';
import ScatterEOS from 'zjubca-scatterjs-plugin-eosjs2';
import {JsonRpc, Api} from 'eosjs';
ScatterJS.plugins( new ScatterEOS() );
const network = ScatterJS.Network.fromJson({
blockchain:'eos',
chainId:'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906',
host:'nodes.get-scatter.com',
port:443,
protocol:'https'
});
const rpc = new JsonRpc(network.fullhost());
ScatterJS.connect('YourAppName', {network}).then(connected => {
if(!connected) return console.error('no scatter');
const eos = ScatterJS.eos(network, Api, {rpc, beta3:true});
ScatterJS.login().then(id => {
if(!id) return console.error('no identity');
const account = ScatterJS.account('eos');
eos.transact({
actions: [{
account: 'eosio.token',
name: 'transfer',
authorization: [{
actor: account.name,
permission: account.authority,
}],
data: {
from: account.name,
to: 'safetransfer',
quantity: '0.0001 EOS',
memo: account.name,
},
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
}).then(res => {
console.log('sent: ', res);
}).catch(err => {
console.error('error: ', err);
});
});
});
These wallets do not require you include any plugins. They run Scatter Protocols inside of their wallet and mimic our existing APIs.
Does your wallet support Scatter Protocols? Issue a Pull Request on the README.md and add it here.
dapp supported blockchains | platform | wallet | libs |
---|---|---|---|
EOSIO, Tron, Ethereum | Scatter Desktop | Desktop | eosjs@16.0.9, eosjs@20+, tronweb, web3 |
EOSIO, Ethereum | Scatter Extension | Desktop | eosjs@16.0.9, web3 |
EOSIO | TokenPocket | Mobile | eosjs@16.0.9 |
EOSIO | MEET.ONE | Mobile | eosjs@16.0.9 |
EOSIO | imToken | Mobile | eosjs@16.0.9 |
EOSIO | PocketEOS | Mobile | eosjs@16.0.9 |
EOSIO | MoreWallet | Mobile | eosjs@16.0.9 |
EOSIO | NOVAWallet | Mobile | eosjs@16.0.9 |
EOSIO | Chaince Wallet | Mobile | eosjs@16.0.9 |
These wallets require a plugin to support. ScatterJS will mutate standardized blockchain library requests for you into their required formats.
dapp supported blockchains | wallet | platform | plugin | libs |
---|---|---|---|---|
EOSIO | Lynx | Mobile | scatterjs-plugin-lynx |
eosjs@20+ |
To use ScatterJS you must have at least the core. From that point forward you can mix-match the plugins you require.
blockchain library | installation command |
---|---|
eosjs | npm i -S zjubca-scatterjs-core zjubca-scatterjs-plugin-eosjs eosjs@16.0.9 |
eosjs2 (@20+) | npm i -S zjubca-scatterjs-core zjubca-scatterjs-plugin-eosjs2 eosjs@20.0.0-beta3 |
As early as you can in your project, instantiate both ScatterJS and your selected plugins.
import ScatterJS from 'zjubca-scatterjs-core';
import ScatterEOS from 'zjubca-scatterjs-plugin-eosjs'
ScatterJS.plugins( new ScatterEOS() );
<script src="zjubca-scatterjs-core.min.js"></script>
<script src="zjubca-scatterjs-plugin-eosjs.min.js"></script>
<script>
ScatterJS.plugins( new ScatterEOS() );
</script>
Networks tell Scatter which blockchain nodes you're going to be working with.
const network = ScatterJS.Network.fromJson({
blockchain:'eos',
chainId:'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906',
host:'nodes.get-scatter.com',
port:443,
protocol:'https'
});
Once you are connected you can then call API methods on ScatterJS
ScatterJS.connect('MyAppName', {network}).then(connected => {
if(!connected) return false;
// ScatterJS.someMethod();
});
You can see full scatterjs-core API docs here
Login with the network passed into ScatterJS.connect
ScatterJS.login().then(...);
Login with multiple networks
ScatterJS.login({accounts:[network1, network2]).then(...);
Logout
ScatterJS.logout().then(...);
After a successful login, the "Identity" will be available at ScatterJS.identity
.
If a user refreshes the page and has already logged in, the ScatterJS.identity
property will be auto-filled.
Because accounts are nested within the Identity there is an easy method for fetching them.
const account = ScatterJS.account('eos')
// Result: {name:'...', authority:'active', publicKey:'...', blockchain:'eos', chainId:'...'}
const account = ScatterJS.account('eth')
// Result: {address:'...', blockchain:'eth', chainId:'1'}
const account = ScatterJS.account('trx')
// Result: {address:'...', blockchain:'trx', chainId:'1'}
const account = ScatterJS.identity.accounts.find(x => {
return x.blockchain === 'eos';
});
Blockchain wrappers wrap the actual blockchain libraries (eosjs, tronweb, web3, etc) that you pass in. That way you don't have to relearn any APIs or be forced to use any specific version.
You can click on the libraries here below to go directly to their respective githubs.
eosjs@16.0.9 ( zjubca-scatterjs-plugin-eosjs )
import Eos from 'eosjs';
const eos = ScatterJS.eos(network, Eos, eosjsOptions);
const result = await eos.transfer(...);
eosjs@20.0.0-beta3 ( zjubca-scatterjs-plugin-eosjs2 )
import {JsonRpc, Api} from 'eosjs'
const rpc = new JsonRpc(network.fullhost());
const eos = ScatterJS.eos(network, Api, {rpc, beta3:true}));
const result = await eos.transact({...});
If you're having trouble packaging or compiling your project you probably need to add a babel transpiler.
npm i -D @babel/runtime
<-- run this command and it should compile.
const eos = scatter.eos(network, Api, { rpc, beta3:true })
Head over to the Scatter Developer Documentation to learn about all the amazing things you can do with Scatter.
There's also a lot more information about proper setup in the Setting up for Web Applications section which will help you get the most out of ScatterJS, and make sure you aren't exposing your users to malicious non-Scatter plugins.