Dev document
- 1.Make sure the user get the Extension
- 2.Connect the blockchain
- 3.Initialize contract / Call the methods of the blockchain
- 4.Call the methods of contract
let nightElfInstance = null;
class NightElfCheck {
constructor() {
const readyMessage = 'NightElf is ready';
let resovleTemp = null;
this.check = new Promise((resolve, reject) => {
if (window.NightElf) {
resolve(readyMessage);
}
setTimeout(() => {
reject({
error: 200001,
message: 'timeout / can not find NightElf / please install the extension'
});
}, 1000);
resovleTemp = resolve;
});
document.addEventListener('NightElf', result => {
console.log('test.js check the status of extension named nightElf: ', result);
resovleTemp(readyMessage);
});
}
static getInstance() {
if (!nightElfInstance) {
nightElfInstance = new NightElfCheck();
return nightElfInstance;
}
return nightElfInstance;
}
}
const nightElfCheck = NightElfCheck.getInstance();
nightElfCheck.check.then(message => {
// connectChain -> Login -> initContract -> call contract methods
});
const aelf = new window.NightElf.AElf({
httpProvider: [
'http://127.0.0.1:8101',
],
appName: 'your own app name'
});
Callback or promise are both ok.
// callback
aelf.chain.getChainStatus((error, result) => {
console.log('>>>>>>>>>>>>> getChainStatus >>>>>>>>>>>>>');
console.log(error, result);
});
// promise
aelf.chain.getChainStatus().then(result => {
console.log('>>>>>>>>>>>>> getChainStatus >>>>>>>>>>>>>');
console.log('promise then', result);
}).catch(error => {
console.log('promise catch', error);
});
Here you can find examples and in-depth information about NightELF's API.