Building an ERC721 non-fungible token smart contract and using metamask to interact with it via a web interface. (PART II)

Daniel Pittman
Coinmonks
11 min readJul 28, 2018

--

Building the Web Interface

We now have a working contract but lets interact with it using a website. You can view a working example deployed on the Ropsten Testnet at Qwoyn.io. Here is the code snippet which I have inserted in to my wordpress site. It’s very basic and needs some love but the functionality is what matters, I will let you make it more beautiful. If you feel like helping me visit my GitHub and create a pull request.

On to the .html:

I have copy and pasted this code from my repo, I recommend visiting GitHub and using the code there if you are implementing this yourself.

Here is a closer look:

Here we have called out required scripts for web3 and ethjs.

This function checks to see if web3 has been injected in to the browser.

This JSON is our contract abi, it will enable us to use the functions in our contract.

Our contract address on the blockchain. Remember we are using the Ropsten Testnet but you may use any ethereum network you have deployed the contract to.

This function initializes our app.

The listenForClicks(token,web3) function asks the user to enter the type, title and description in a simple prompt. This information is used in the buyToken function within our smart contract during execution.

Above is that implementation. Finally lets take a look at the last line.

Here we create a button which executes our contract via updateChain.

Go to Qwoyn.io
Pick a type.
Pick a title
Enter a description
Click “Update ETC Blockchain”
Find your transaction id by pressing F12 and opening the browser console.

I hope you have enjoyed this short tutorial on building dApps. Don’t hesitate to ask questions!

Our developers volunteer their time but happily accept donations:

ETC: 0x007e60C669cf96dC32655d1Eb1c1eBcf96459975

BTC: 15X8rjV7EaTtsC6BhrffuqH28LZpqZ9Tdi

BCC: 1KrwR96hbCrLavAaWkXz2oy2F51ryohme1

ETH: 0x00c24b3346AFc5c3710AFb27C86431ebB5ce8163

--

--