Skip to content

Instantly share code, notes, and snippets.

@xboston
Last active July 7, 2020 20:43
Show Gist options
  • Save xboston/e6ffcdb6377f7b8bfe6fa3aeb6e7ca17 to your computer and use it in GitHub Desktop.
Save xboston/e6ffcdb6377f7b8bfe6fa3aeb6e7ca17 to your computer and use it in GitHub Desktop.
// step 0: npm i metahash-js
// step 1: create file index.js
const MetaHash = require('metahash-js');
{ // create key
const Wallet = MetaHash.Wallet;
const wallet = new Wallet();
console.log('you new metahash key', {
address: wallet.address,
publicKey: wallet.publicKey,
privateKey: wallet.privateKey
})
}
{ // using api
const API = MetaHash.API;
const api = new API();
const address = '0x00fa2a5279f8f0fd2f0f9d3280ad70403f01f9d62f52373833';
api.fetchBalance({ address: address }).then((result) => {
console.log('fetchBalance', result);
});
api.fetchHistory({ address: address, countTxs: 5 }).then((result) => {
console.log('fetchHistory', result);
});
api.getTx({ hash: '7f75fdfba4bc2fe674b37d4730533edf9cb047f1f93b4f6687f4cab819eb88b6' }).then((result) => {
console.log('getTx', result);
});
api.fetchBalance({ address: address }).then((result) => {
const currentBalance = (result.received - result.spent) / 1e6;
console.log('current balance', { currentBalance });
});
}
// step 2: node index.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment