Loading...
Many times when the dapp is built using any trc10, trc20 or trc721 tokens, the user will have to find that particular token address and add it manually to their wallet. If there is any functionality in which the dapp itself adds the required tokens in user wallet would be a great ! so lets discuss how to do this using tronweb and tronlink.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<button onclick="gettronweb()">Can you get tronweb from tronlink?</button>
<script>
function gettronweb(){
if(window.tronWeb && window.tronWeb.defaultAddress.base58){
document.write("Yes, catch it:",window.tronWeb.defaultAddress.base58)
}
}
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
var obj = setInterval(async ()=>{
if (window.tronWeb && window.tronWeb.defaultAddress.base58) {
clearInterval(obj)
var tronweb = window.tronWeb
var tx = await tronweb.request({method: 'wallet_watchAsset',
params:{type: 'trc20',
options: {address: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'},
},
}
)
}
}, 10)
</script>
</body>
</html>
the address will specify which token is being added in users tronlink wallet.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
var obj = setInterval(async ()=>{
if (window.tronWeb && window.tronWeb.defaultAddress.base58) {
clearInterval(obj)
var tronweb = window.tronWeb
var tx = await tronweb.request({method: 'wallet_watchAsset',
params:{type: 'trc10',
options: {address: '1002000'},
},
}
)
}
}, 10)
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script>
var obj = setInterval(async ()=>{
if (window.tronWeb && window.tronWeb.defaultAddress.base58) {
clearInterval(obj)
var tronweb = window.tronWeb
var tx = await tronweb.request({method: 'wallet_watchAsset',
params:{type: 'trc721',
options: {address: 'TCzUYnFSwtH2bJkynGB46tWxWjdTQqL1SG'},
},
}
)
}
}, 10)
</script>
</body>
</html>