注:谷歌浏览器需要安装tronlink钱包 https://www.tronlink.org/templatediv class=helloh1{{ msg }}/h1button @click=linkWallet连接钱包/buttonbutton @click=getBalance获取钱包余额/butto...
注:谷歌浏览器需要安装tronlink钱包 https://www.tronlink.org/
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<button @click="linkWallet">
连接钱包
</button>
<button @click="getBalance">
获取钱包余额
</button>
<button @click="transaction">
TRX转账交易
</button>
<button @click="transactionToken">
TRX-ERC20转账交易
</button>
<button @click="transactionContract">
合约方法调用
</button>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
data () {
return {
msg: 'tron-web-dapp',
tronWeb:null,
walletAddress:null
}
},
mounted () {
if(window.tronWeb){
this.tronWeb = window.tronWeb;
console.log(this.tronWeb)
this.walletAddress = this.tronWeb.defaultAddress.base58;
}
},
methods: {
linkWallet(){
if(window.tronWeb){
this.tronWeb = window.tronWeb;
console.log(window.tronWeb)
this.walletAddress = this.tronWeb.defaultAddress.base58;
console.log(this.tronWeb.defaultAddress.base58)
}
},
//查询钱包余额
async getBalance() {
//当前连接的钱包地址获取 window.tronWeb.defaultAddress.base58
var balance = await this.tronWeb.trx.getBalance(this.walletAddress);
console.log("balance=",balance)
},
//trx转账交易
async transaction() {
var tx = await this.tronWeb.transactionBuilder.sendTrx(
"TN9RRaXkCFtTXRso2GdTZxSxxwufzxLQPP",10 * Math.pow(10,6),this.walletAddress
);
var signedTx = await this.tronWeb.trx.sign(tx);
var broastTx = await this.tronWeb.trx.sendRawTransaction(signedTx);
console.log(broastTx)
},
//trx-token转账交易
async transactionToken() {
//转账方式1
let contract = await this.tronWeb.contract().at("TURwoLuFy7maq1Vea7wVwRNz3HgmcAsJzb");
let result = await contract.transfer(
"TN9RRaXkCFtTXRso2GdTZxSxxwufzxLQPP",
this.tronWeb.toHex(55 * Math.pow(10,18))
).send({
feeLimit: 10000000
}).then(output => {console.log('- Output:', output, '\n');});
console.log('result: ', result);
//转账方式2
/*const parameter = [{type:'address',value:'TN9RRaXkCFtTXRso2GdTZxSxxwufzxLQPP'},{type:'uint256',value:this.tronWeb.toHex(25 * Math.pow(10,18))}]
var tx = await this.tronWeb.transactionBuilder.triggerSmartContract("TURwoLuFy7maq1Vea7wVwRNz3HgmcAsJzb", "transfer(address,uint256)", {},parameter,this.walletAddress);
var signedTx = await this.tronWeb.trx.sign(tx.transaction);
var broastTx = await this.tronWeb.trx.sendRawTransaction(signedTx);
console.log(broastTx)*/
/*let contract = await this.tronWeb.contract().at("TURwoLuFy7maq1Vea7wVwRNz3HgmcAsJzb");
let result1 = await contract.decimals().call();
console.log('result: ', result1);*/
},
//调用合约中的方法
async transactionContract(){
//调用方式1
/*let contract = await this.tronWeb.contract().at("TSbJGFA8UyYGTuXBRbYB2GJeh2CY1X5F4d");
console.log("contract=",contract)
let result = await contract.registrationExt(
"TN9RRaXkCFtTXRso2GdTZxSxxwufzxLQPP"
).send({
callValue: this.tronWeb.toHex(25 * Math.pow(10,6)),//发送TRX余额
feeLimit: 10000000
}).then(output => {console.log('- Output:', output, '\n');});
console.log('result: ', result)*/
//调用方式2
const parameter = [{type:'address',value:'TN9RRaXkCFtTXRso2GdTZxSxxwufzxLQPP'}];
var tx = await this.tronWeb.transactionBuilder.triggerSmartContract(
"TSbJGFA8UyYGTuXBRbYB2GJeh2CY1X5F4d",
"registrationExt(address)",
{},
parameter,
this.walletAddress
);
var signedTx = await this.tronWeb.trx.sign(tx.transaction);
var broastTx = await this.tronWeb.trx.sendRawTransaction(signedTx);
console.log(broastTx)
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
font-weight: normal;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>
唤醒tronlink钱包支付确认
学如逆水行舟,不进则退。心似平原跑马,易放难收。【区块链】【系统/网络/运维】【云计算/大数据】【数据库】【移动开发】【后端开发】【游戏开发】【UI设计】【微服务】【爬虫】【Java】【Go】【C++】【PHP】【Python】【Android/IOS】【HTML/CSS】【JavaScript】【Node】【VUE】【ReactNaive】。。。
欢迎各位大神萌新一起专研分享各行各业技术!
IT全栈工程师技术交流群:593674370
沃梦达教程
本文标题为:TRON波场DAPP对接(tronWeb+vue)
基础教程推荐
猜你喜欢
- 在实战中可能碰到的几种ajax请求方法详解 2023-02-01
- JS滚动到顶部踩坑解决记录 2023-07-10
- HTML clearfix清除浮动讲解 2022-11-20
- cocos creator游戏实现loading加载页面,游戏启动加载动画 2022-10-29
- Javascript Bootstrap的网格系统,导航栏和轮播详解 2023-08-11
- 使用ajax跨域调用springboot框架的api传输文件 2023-02-23
- uniapp开发微信小程序自定义顶部导航栏功能实例 2022-10-21
- Ajax+smarty技术实现无刷新分页 2022-12-15
- Ajax发送和接收请求 2022-12-15
- 关于Ajax跨域问题及解决方案详析 2023-02-23