AgoraLive
AgoraLive

Reputation: 89

Tronlink integration

According to this site:

https://developers.tron.network/docs/tronlink-integration

I am suppose to be able to connect ANY website to TronWeb, following this code:

<!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>

This however does not work when I try to do it, could somebody explain to why?

I have tronlink (Chrome extension) installed, and it works on all other sites, so that's not the issue.

Or am I missing something?

Upvotes: 0

Views: 4268

Answers (4)

Matthew
Matthew

Reputation: 141

You need to call this first:

await window.tronLink.request({ method: 'tron_requestAccounts' })

Upvotes: 0

josh hoffer
josh hoffer

Reputation: 394

you need to install tronweb and use the methods provided . that example is kind of just like a skeleton to show you how it would be called . but there needs to be more then just that file.

im newer then you most likely at coding lol so i am probably wrong just giving my 2cents

Upvotes: 1

Jetso Analin
Jetso Analin

Reputation: 1

Tron Development seems tricky somehow for new users with lack of proper documentation.

Unlike Web3/Metamask which can work on localhost itself for checking and development tron seems to not work with "insecure" network/server.

You need a SSL certified server in-order to run it properly (yes its strange might be for some security ! who knows).

What i did while testing is created a JS file where i've written all tronlink (TronWeb Extension) related code and used "index.html" file to interact with it (For some reason !)

Now what I did was hosted this index.html file along with my JS code for tronlink interaction to Github Pages ! Yes for free + you get Github's SSL pre installed server and that's enough for your program to run and test.

Note: Github pages needs your repository to be kept public inorder to host it. (Not preferred for private projects)

You can also host it in your personal AWS with SSL certificate or any other Servers with SSL certificate.

Hope this helps all with this same issue !

Upvotes: 0

AgoraLive
AgoraLive

Reputation: 89

It might seem that Tronlink requires a SSL server before running....

Works on a SSL certified server....

Upvotes: 0

Related Questions