Created
March 15, 2019 10:22
-
-
Save joeneldeasis/4b72f1923e3a4bdfc356148a79257ede to your computer and use it in GitHub Desktop.
This file contains 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
const Web3 = require('web3'); | |
const tokenAbi = [ | |
{ | |
"constant":true, | |
"inputs":[ | |
], | |
"name":"name", | |
"outputs":[ | |
{ | |
"name":"", | |
"type":"string" | |
} | |
], | |
"payable":false, | |
"type":"function" | |
}, | |
{ | |
"constant":false, | |
"inputs":[ | |
{ | |
"name":"_spender", | |
"type":"address" | |
}, | |
{ | |
"name":"_value", | |
"type":"uint256" | |
} | |
], | |
"name":"approve", | |
"outputs":[ | |
{ | |
"name":"success", | |
"type":"bool" | |
} | |
], | |
"payable":false, | |
"type":"function" | |
}, | |
{ | |
"constant":true, | |
"inputs":[ | |
], | |
"name":"totalSupply", | |
"outputs":[ | |
{ | |
"name":"", | |
"type":"uint256" | |
} | |
], | |
"payable":false, | |
"type":"function" | |
}, | |
{ | |
"constant":false, | |
"inputs":[ | |
{ | |
"name":"_from", | |
"type":"address" | |
}, | |
{ | |
"name":"_to", | |
"type":"address" | |
}, | |
{ | |
"name":"_value", | |
"type":"uint256" | |
} | |
], | |
"name":"transferFrom", | |
"outputs":[ | |
{ | |
"name":"success", | |
"type":"bool" | |
} | |
], | |
"payable":false, | |
"type":"function" | |
}, | |
{ | |
"constant":true, | |
"inputs":[ | |
], | |
"name":"decimals", | |
"outputs":[ | |
{ | |
"name":"", | |
"type":"uint8" | |
} | |
], | |
"payable":false, | |
"type":"function" | |
}, | |
{ | |
"constant":false, | |
"inputs":[ | |
{ | |
"name":"amount", | |
"type":"uint256" | |
} | |
], | |
"name":"withdrawEther", | |
"outputs":[ | |
], | |
"payable":false, | |
"type":"function" | |
}, | |
{ | |
"constant":false, | |
"inputs":[ | |
{ | |
"name":"_value", | |
"type":"uint256" | |
} | |
], | |
"name":"burn", | |
"outputs":[ | |
{ | |
"name":"success", | |
"type":"bool" | |
} | |
], | |
"payable":false, | |
"type":"function" | |
}, | |
{ | |
"constant":false, | |
"inputs":[ | |
{ | |
"name":"_value", | |
"type":"uint256" | |
} | |
], | |
"name":"unfreeze", | |
"outputs":[ | |
{ | |
"name":"success", | |
"type":"bool" | |
} | |
], | |
"payable":false, | |
"type":"function" | |
}, | |
{ | |
"constant":true, | |
"inputs":[ | |
{ | |
"name":"", | |
"type":"address" | |
} | |
], | |
"name":"balanceOf", | |
"outputs":[ | |
{ | |
"name":"", | |
"type":"uint256" | |
} | |
], | |
"payable":false, | |
"type":"function" | |
}, | |
{ | |
"constant":true, | |
"inputs":[ | |
], | |
"name":"owner", | |
"outputs":[ | |
{ | |
"name":"", | |
"type":"address" | |
} | |
], | |
"payable":false, | |
"type":"function" | |
}, | |
{ | |
"constant":true, | |
"inputs":[ | |
], | |
"name":"symbol", | |
"outputs":[ | |
{ | |
"name":"", | |
"type":"string" | |
} | |
], | |
"payable":false, | |
"type":"function" | |
}, | |
{ | |
"constant":false, | |
"inputs":[ | |
{ | |
"name":"_to", | |
"type":"address" | |
}, | |
{ | |
"name":"_value", | |
"type":"uint256" | |
} | |
], | |
"name":"transfer", | |
"outputs":[ | |
], | |
"payable":false, | |
"type":"function" | |
}, | |
{ | |
"constant":true, | |
"inputs":[ | |
{ | |
"name":"", | |
"type":"address" | |
} | |
], | |
"name":"freezeOf", | |
"outputs":[ | |
{ | |
"name":"", | |
"type":"uint256" | |
} | |
], | |
"payable":false, | |
"type":"function" | |
}, | |
{ | |
"constant":false, | |
"inputs":[ | |
{ | |
"name":"_value", | |
"type":"uint256" | |
} | |
], | |
"name":"freeze", | |
"outputs":[ | |
{ | |
"name":"success", | |
"type":"bool" | |
} | |
], | |
"payable":false, | |
"type":"function" | |
}, | |
{ | |
"constant":true, | |
"inputs":[ | |
{ | |
"name":"", | |
"type":"address" | |
}, | |
{ | |
"name":"", | |
"type":"address" | |
} | |
], | |
"name":"allowance", | |
"outputs":[ | |
{ | |
"name":"", | |
"type":"uint256" | |
} | |
], | |
"payable":false, | |
"type":"function" | |
}, | |
{ | |
"inputs":[ | |
{ | |
"name":"initialSupply", | |
"type":"uint256" | |
}, | |
{ | |
"name":"tokenName", | |
"type":"string" | |
}, | |
{ | |
"name":"decimalUnits", | |
"type":"uint8" | |
}, | |
{ | |
"name":"tokenSymbol", | |
"type":"string" | |
} | |
], | |
"payable":false, | |
"type":"constructor" | |
}, | |
{ | |
"payable":true, | |
"type":"fallback" | |
}, | |
{ | |
"anonymous":false, | |
"inputs":[ | |
{ | |
"indexed":true, | |
"name":"from", | |
"type":"address" | |
}, | |
{ | |
"indexed":true, | |
"name":"to", | |
"type":"address" | |
}, | |
{ | |
"indexed":false, | |
"name":"value", | |
"type":"uint256" | |
} | |
], | |
"name":"Transfer", | |
"type":"event" | |
}, | |
{ | |
"anonymous":false, | |
"inputs":[ | |
{ | |
"indexed":true, | |
"name":"from", | |
"type":"address" | |
}, | |
{ | |
"indexed":false, | |
"name":"value", | |
"type":"uint256" | |
} | |
], | |
"name":"Burn", | |
"type":"event" | |
}, | |
{ | |
"anonymous":false, | |
"inputs":[ | |
{ | |
"indexed":true, | |
"name":"from", | |
"type":"address" | |
}, | |
{ | |
"indexed":false, | |
"name":"value", | |
"type":"uint256" | |
} | |
], | |
"name":"Freeze", | |
"type":"event" | |
}, | |
{ | |
"anonymous":false, | |
"inputs":[ | |
{ | |
"indexed":true, | |
"name":"from", | |
"type":"address" | |
}, | |
{ | |
"indexed":false, | |
"name":"value", | |
"type":"uint256" | |
} | |
], | |
"name":"Unfreeze", | |
"type":"event" | |
} | |
]; | |
// const web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.infura.io/v3/xxxxxxxxxxxxxxxxxxx')); //infura is working | |
const web3 = new Web3(new Web3.providers.HttpProvider('http://xxx.xxx.xxx:8545')); //use here your own geth node | |
const contract = web3.eth.Contract(tokenAbi, '0xB8c77482e45F1F44dE1745F52C74426C631bDD52', { | |
from: 'd583b306d65c4aa1821970029414acc3def71f36', | |
}); | |
contract.methods | |
.balanceOf('d583b306d65c4aa1821970029414acc3def71f36') | |
.call() | |
.then((balance) => { | |
console.log(`Token Balance ${web3.utils.fromWei(balance)}`) | |
}).catch(error => { | |
console.log(error) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment