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
// Using thor-devkit.js | |
const Transaction = require('thor-devkit/dist/transaction').Transaction | |
// Construct transaction body. | |
const txBody = { | |
// Test-net: 0x27, Main-net: 0x4a. | |
chainTag: 0x27, | |
// After which block this tx should happen? | |
// 16 characters of block ID. | |
blockRef: '0x004984e1064ed410', |
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
pragma solidity ^0.5.11; | |
contract Hello { | |
uint public counter; | |
constructor () public { | |
counter = 0; | |
} | |
function increaseAmount () public { |
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
/** | |
* Get token amount of holder from a contract. | |
* @param {String} addressContract 0x started address. | |
* @param {String} addressHolder 0x started address. | |
*/ | |
async function getTokenBalance (addressContract, addressHolder) { | |
const balanceOfABI = { | |
'constant': true, | |
'inputs': [ | |
{ |
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
<template> | |
<div id="app"> | |
<div> | |
<b-card style="max-width: 30rem;" :header="myaddress"> | |
<p>{{myamount}} <span class="text-primary">VTHO</span></p> | |
<b-form-group label="To Address:" label-for="toaddress"> | |
<b-form-input id="toaddress" v-model.trim="toaddress"></b-form-input> | |
</b-form-group> |
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
<template> | |
<div id="app"> | |
<div> | |
<b-card style="max-width: 30rem;" :header="myaddress"> | |
<p>{{myamount}} <span class="text-primary">VTHO</span></p> | |
<b-form-group label="To Address:" label-for="toaddress"> | |
<b-form-input id="toaddress" v-model.trim="toaddress"></b-form-input> | |
</b-form-group> |
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
<script> | |
methods: { | |
// ... add after refreshTokenBalance() | |
transfer () { // Confrim and send out a transfer. | |
const evmAmount = utils.humanToEVM(this.toamount.toString(), 18) | |
operations.transferToken(this.contract, this.myaddress, this.toaddress, evmAmount, this.toamount, 'VTHO') | |
.then(result => {alert('success!')}) | |
.catch(e => {alert('failed!')}) | |
} | |
} |
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
<!-- Continue with the App.vue --> | |
<script> | |
const operations = require('./operations.js') | |
const utils = require('./utils.js') | |
export default { | |
data() { | |
return { | |
myaddress: '0xa7a609b928c4eac077d0e5640f3fa650746c4fcf', | |
myamount: 0, |
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
const BigNumber = require('bignumber.js') | |
const DECIMALS = function (points) { | |
return new BigNumber(10 ** points) // Decimals = 18 on VTHO and most contracts. | |
} | |
/** | |
* Turn a string to big number. | |
* @param {String} aString a number string. | |
*/ | |
const makeBN = function (aString) { |
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
export { | |
getTokenBalance, | |
transferToken | |
} |
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) { |