Golang Backend Server – Connecting with Metamask for Ethereum Applications

ethergo-ethereumgolang

I'm trying to build a Ticket-Office project in one of my courses at the University.

The project uses a backend server (which I'm writing in Golang) and it should be able to deploy and use smart contracts; to be able to create events (concerts and sports for example), tickets for these events, and the ability for the end user to 'purchase' them.

The ticket purchase should be based on smart contract transactions.
I already figured out how to connect to the Ropsten test network (where all my contracts will live).
My issue is, that I can't figure out how to connect users(those who potentially will want to buy a ticket) Metamask account to my service.
I can't find an example for that either.

Any suggestions?
Thanks ahead!

Best Answer

When you say that you want to connect users' Metamask account to your service, you are actually referring to be able to make Metamask send the transactions(basically sign them using the user's private key and then submit to the network) for the user.

This is achieved using the window.web3 object's provider. The object is injected into the browser window by Metamask. You can access this object and the provider through JavaScript that gets executed on the browser.

You cannot do the signing using your go server code because the user's private key cannot be exposed and thus should not leave the client side. So the signing should take place in the browser. You have to use some front end code for this purpose. You may be able to do this by serving some JavaScript files from your go server. But in that case mostly you will be stuck with the old web3 version injected by Metamask.

Related Topic