Created
March 5, 2019 09:35
-
-
Save laalaguer/585709e218523daf1642d29371f9af30 to your computer and use it in GitHub Desktop.
Add sign-and-send code to the operations.js
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
/** | |
* Transfer token from one to another. | |
* @param {String} addressContract Contract address. | |
* @param {String} signerAddress Enforce who signs the transaction. | |
* @param {String} toAddress Receiver of transfer. | |
* @param {String} amountEVM Big number in string. | |
* @param {Number} amountHuman Normal number in Javascript. | |
* @param {String} symbol Symbol of token. | |
*/ | |
async function transferToken (addressContract, signerAddress, toAddress, amountEVM, amountHuman, symbol) { | |
const transferABI = { | |
'constant': false, | |
'inputs': [ | |
{ | |
'name': '_to', | |
'type': 'address' | |
}, | |
{ | |
'name': '_value', | |
'type': 'uint256' | |
} | |
], | |
'name': 'transfer', | |
'outputs': [ | |
{ | |
'name': '', | |
'type': 'bool' | |
} | |
], | |
'payable': false, | |
'stateMutability': 'nonpayable', | |
'type': 'function' | |
} | |
// eslint-disable-next-line | |
const transferMethod = connex.thor.account(addressContract).method(transferABI) | |
const transferClause = transferMethod.asClause(toAddress, amountEVM) | |
// eslint-disable-next-line | |
const signingService = connex.vendor.sign('tx') | |
signingService | |
.signer(signerAddress) // Enforce signer | |
.comment('Token transfer: ' + amountHuman.toString() + ' ' + symbol) | |
let transactionInfo = await signingService.request([ | |
{ | |
comment: 'Hello! Transfer Demo!', | |
...transferClause | |
} | |
]) | |
return transactionInfo | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment