Skip to content

Instantly share code, notes, and snippets.

@epexa
Created March 7, 2018 20:34
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 epexa/f5c169dca79ee80f04450ef57f66b6a0 to your computer and use it in GitHub Desktop.
Save epexa/f5c169dca79ee80f04450ef57f66b6a0 to your computer and use it in GitHub Desktop.
signTransaction and getTransaction on blockchain Golos on HTML
<script src="https://wzrd.in/standalone/buffer"></script>
<script src="https://momentjs.com/downloads/moment.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/golos-js@0.5.30/dist/golos.min.js"></script>
<script>
// switch to testnet
golos.config.set('websocket', 'wss://ws.testnet3.golos.io');
golos.config.set('chain_id', '5876894a41e6361bde2e73278f07340f2eb8b41c2facd29099de9deef6cdb679');
// private posting key
let wif = '5J...';
// https://github.com/GolosChain/golos-js/blob/master/doc/README.md#vote
let operations = [
// vote operation
['vote', {
// params for vote operation
'author': 'golos-test',
'permlink': '7apsm1-qwerty',
'voter': 'test',
'weight': 10000
}]
];
// https://github.com/GolosChain/golos-js/blob/master/doc/README.md#get-dynamic-global-properties
golos.api.getDynamicGlobalProperties(function(err, properties) {
console.log(err, 'getDynamicGlobalProperties: ', properties);
// https://github.com/GolosChain/golos-js/blob/master/doc/README.md#get-block
golos.api.getBlock(properties.head_block_number - 2, function(err, block) {
console.log(err, 'getBlock: ', block);
let trx = {
ref_block_num: (properties.head_block_number - 3) & 0xFFFF,
ref_block_prefix: buffer.Buffer(block.previous, 'hex').readUInt32LE(4),
expiration: moment(properties.time).add(1, 'hours').format('YYYY-MM-DDTHH:mm:ss'), // 2018-03-07T18:10:21
operations: operations,
signatures: [],
};
let keys = {
posting: wif
};
// https://github.com/GolosChain/golos-js/blob/master/doc/README.md#sign-transaction
trx = golos.auth.signTransaction(trx, keys);
console.log('signTransaction: ', trx);
// https://github.com/GolosChain/golos-js/blob/master/doc/README.md#get-transaction-hex
golos.api.getTransactionHex(trx, function(err, result) {
console.log(err, 'getTransactionHex: ' + result);
});
// https://github.com/GolosChain/golos-js/blob/master/doc/README.md#broadcast-transaction-synchronous
golos.api.broadcastTransactionSynchronous(trx, function(err, trxData) {
console.log(err, 'broadcastTransactionSynchronous: ', trxData);
// https://github.com/GolosChain/golos-js/blob/master/doc/README.md#get-transaction
golos.api.getTransaction(trxData.id, function(err, result) {
console.log(err, 'getTransaction: ', result);
});
});
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment