All Evo Core classes reside in the Evo. namespace.
Evo.init($ => {
// $ is the Evo.Core instance
});Evo.ERR_WAIT: An instance of Evo Core is already running in another window of the same origin. When all other windows are closed, the success callback will be invoked.Evo.ERR_UNSUPPORTED: This browser is not supported.Evo.ERR_UNKNOWN: An unknown error occured while loading.Evo.Wallet.ERR_INVALID_WALLET_SEED: An invalid wallet seed has been provided.
Evo.init($ => {
// $ is the Evo.Core instance
}, code => {
switch (code) {
case Evo.ERR_WAIT:
alert('Another Evo instance is already running');
break;
case Evo.ERR_UNSUPPORTED:
alert('Browser not supported');
break;
case Evo.Wallet.ERR_INVALID_WALLET_SEED:
alert("Invalid wallet seed");
break;
default:
alert('Evo initialization error');
break;
}
});You can pass some options to initialization.
| Option | Description |
|---|---|
| walletSeed | Wallet seed (See Evo.Wallet) |
const options = {
walletSeed: "d6a651dcc13dab2e9d05d..."
}
Evo.init($ => {
// $ is the Evo.Core instance
}, code => {
// Handle errors
},
options
);Evo.get().then($ => {
// $ is the Evo.Core instance
});network: Evo.Networkconsensus: Evo.Consensusaccounts: Evo.Accountsblockchain: Evo.Blockchainmempool: Evo.Mempoolwallet: Evo.Walletminer: Evo.Miner
No public methods.
No events.
The network will not connect automatically, call $.network.connect() to do so.
peerCountpeerCountWebSocketpeerCountWebRtcbytesReceivedbytesSent
connect()disconnect()
peers-changedpeer-joined (peer)peer-left (peer)
Connect to the network:
$.network.connect()Listen for peer connections:
$.network.on('peers-changed', () => console.log('Peers changed'));
$.network.on('peer-joined', peer => console.log(`Peer ${peer} joined`));
$.network.on('peer-left', peer => console.log(`Peer ${peer} left`));established
No public methods.
syncing (targetHeight)establishedlost
Listen for established event:
$.consensus.on('established', () => console.log('consensus established!'))No public properties.
getBalance(address)commitBlock(block)revertBlock(block)async hash()
<<base64(address)>> (balance, address)when balance of address changes.
Query an account's balance:
$.accounts.getBalance(<<address>>).then(balance => {
console.log(balance.value)
console.log(balance.nonce)
})Listen for an account balance change:
$.accounts.on('a09rjiARiVYh2zJS0/1pYKZg4/A=').then(balance => {
console.log(balance)
})headheadHashtotalWorkheightpathbusy
pushBlock(block)getBlock(hash)getNextCompactTarget()async accountsHash()
head-changedready
Show the blockchain sync progress
let targetHeight = 0;
$.consensus.on('syncing', _targetHeight => {
targetHeight = _targetHeight;
})
$.blockchain.on('head-changed', () => {
const height = $.blockchain.height;
ui.setProgress(height / targetHeight);
})No public properties.
pushTransaction(transaction)getTransaction(hash)getTransactions(maxCount = 5000)
transaction-addedtransactions-ready
addresspublicKey
createTransaction(recipientAddr, value, fee, nonce)dump()
No events.
Create a transaction:
$.wallet.createTransaction(recipientAddr, value, fee, nonce).then(transaction => {
console.log(transaction)
})Dump and restore wallet:
var walletSeed = $.wallet.dump();
var restoredWallet = await Wallet.load(walletSeed);Mining should not start before consensus is established and stop when consensus is lost. The Miner does not explicitely enforce this, but callers should ensure this behavior.
// Start mining automatically once consensus is (re-)established.
$.consensus.on('established', () => $.miner.startWork());
// Stop mining when consensus is lost. All clients should do this!
$.consensus.on('lost', () => $.miner.stopWork());workingaddresshashrate
startWork()stopWork()
startstopblock-minedhashrate-changed