Skip to content

Instantly share code, notes, and snippets.

@oojr
Created January 6, 2018 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oojr/28d608aa67aaf8858dc227498ef69218 to your computer and use it in GitHub Desktop.
Save oojr/28d608aa67aaf8858dc227498ef69218 to your computer and use it in GitHub Desktop.
bch sample code
// check balance
const blocktrail = require('blocktrail-sdk');
const client = blocktrail.BlocktrailSDK({
apiKey: '',
apiSecret: '',
network: 'BCC',
testnet: true
});
client.address('2NFc5owQ7eeD2V3Qx4ZNuTxqcZ9LSrbwXP7', (err, address) => {
console.log('Total Balance', address.balance);
});
client.blockLatest(function(err, block) {
console.log(block.hash);
});
// send payment
const blocktrail = require('blocktrail-sdk');
const client = blocktrail.BlocktrailSDK({
apiKey: '',
apiSecret: '',
network: 'BCC',
testnet: true
});
const value = blocktrail.toSatoshi(1.1);
let myWallet;
client.createNewWallet('mywallet', 'mypass', function(err, wallet, backupInfo) {
myWallet = wallet;
});
client.initWallet('mywallet', 'mypass', function(err, wallet) {
console.log('Error', err);
console.log('Wallet', wallet);
const value = blocktrail.toSatoshi(3);
wallet.pay(
{ '2NGCeykHMPXEgyphnQLrX4UgmstGqRcyLqt': value },
null,
false,
true,
blocktrail.Wallet.FEE_STRATEGY_BASE_FEE,
function(err, result) {
console.log('tx result', result);
}
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment