Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Build delegated tx by thor-devkit.js
const originPriv = Buffer.from('c962bfd916c0f8d4c1866b11a24802815cf58ba981354fad0ac734d0217cfe73', 'hex')
const txOrigin = cry.publicKeyToAddress(cry.secp256k1.derivePublicKey(originPriv))
const delegatorPriv = Buffer.from('dce1443bd2ef0c2631adc1c67e5c93f13dc23a41c18b536effbbdcbcdb96fb65', 'hex')
const delegator = cry.publicKeyToAddress(cry.secp256k1.derivePublicKey(delegatorPriv))
const tx = new Transaction({
chainTag: 0x27,
blockRef: '0x002b99c540c4e267',
expiration: 30 * 8640, // Expires after 30 days
clauses: [{
to: '0xd3ae78222beadb038203be21ed5ce7c9b1bff602',
value: 0,
data: '0x'
}],
gasPriceCoef: 0,
gas: 50000,
dependsOn: null,
nonce: '0xa2b5232b', // Random number
reserved: {
features: 1
}
})
// The hash for tx origin to sign
const originHash = tx.signingHash()
// The hash for delegator to sign
const delegatorHash = tx.signingHash('0x' + txOrigin.toString('hex'))
const sig = Buffer.concat([
cry.secp256k1.sign(originHash, originPriv),
cry.secp256k1.sign(delegatorHash, delegatorPriv)
])
tx.signature = sig
const rawTx = '0x' + tx.encode().toString('hex')
@ip-config

This comment has been minimized.

Copy link

commented May 27, 2019

Working Prefect @testnet ^^'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.