Skip to content

Instantly share code, notes, and snippets.

Last active January 13, 2020 08:48
What would you like to do?
sponsor using Express framework
const express = require('express')
const cry = require('thor-devkit/dist/cry')
const Transaction = require('thor-devkit/dist/transaction').Transaction
const app = express()
const port = 3000'/', function(req, res) {
// Re-construct the transaction from the request.
const tx = new Transaction(req.body['txBody'])
// Extract 'sender' address from request.
const sender = req.body['sender']
// Compute the sponsor hash.
const sponsorHash = tx.signingHash(sender)
// Sponsor account (with money):
// 0x126cdb344f476f25b9fb2050513f425a82f71046
const sponsorPriv = Buffer.from(
// Compute the sponsor signature with hash+private key.
const signature = cry.secp256k1.sign(sponsorHash, sponsorPriv)
// Send back the signature.
'sponsor_signature': signature.toString('hex')
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment