Last active
July 7, 2020 20:43
-
-
Save xboston/e6ffcdb6377f7b8bfe6fa3aeb6e7ca17 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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