<p align="center">
<img width=1000" height="350" src="https://media.giphy.com/media/11MKLWSDvMVSp2/giphy.gif">
</p>
# Let's put Taj Mahal on sale !!
Yes i am not out of my mind and it is completely possible with the help of blockchain technology.Of course Blockchian will protect us from intervention of third parties.
What we will be building is a digital asset (ERC721 token) on blockchain with the help of solidity(by writing smart contracts).We will then use IPFS to deploy our Dapp.
## Setup Environment
We need to get hold of truffle,get it via ```npm install -g truffle```.You need to have Node.js v6+ LTS and npm (comes with Node) and Git too.This tutorial is best suited for unix environment.
We would also be needing ganache or testrpc for local deployment.
## Let's conspire to sell Taj Mahal
* Open Terminal
* Make a suitable folder with ```mkdir tajmahal``` and navigate into folder ```cd tajmahal```
* Now initialize the project with ```truffle init``` .
* You will notice ***contracts migrations test truffle-config.js truffle.js*** directories and files being added to folder.
* __contracts/:__ Contains the Solidity source files for our smart contracts. There is an important contract in here called Migrations.sol.
* __migrations/:__ Truffle uses a migration system to handle smart contract deployments. A migration is an additional special smart contract that keeps track of changes.
* __test/:__ Contains both JavaScript and Solidity tests for our smart contracts
* __truffle.js:__ Truffle configuration file
* In __truffle.js__ replace the stuff with following code.
```javascript
// Allows us to use ES6 in our migrations and tests.
// require('babel-register')
// require('babel-polyfill')
module.exports = {
networks: {
development: {
host: '127.0.0.1',
port: 7545,
network_id: '*', // Match any network id
}
},
};
```
* Now add the following contracts in the **contracts** directory and then hit ```truffle compile```
* I have created Tajmahal.sol (because written in soilidty) that contains buisness logic.According to this contract ONLY ONE Tajmahal can be created.It will be non fungible an unique as it implement erc721 standards.Since we do not want some overflow in our arithmetic operations we have used __safemath.sol__ library from openzepplin.__ownable.sol__ is again from openzepplin for restricting use of some contract functions to owners.
* [Tajmahal.sol](https://github.com/phunsukwangdu/ERC721-fullstack-Dapp-Tutorial/blob/master/contracts/Tajmahal.sol)
* [erc721.sol](https://github.com/phunsukwangdu/ERC721-fullstack-Dapp-Tutorial/blob/master/contracts/erc721.sol)
* [ownable.sol](https://github.com/phunsukwangdu/ERC721-fullstack-Dapp-Tutorial/blob/master/contracts/ownable.sol)
* [safemath.sol](https://github.com/phunsukwangdu/ERC721-fullstack-Dapp-Tutorial/blob/master/contracts/safemath.sol)
* Since we have smart contracts in place we need to migrate these contract.But before we proceed to this step we need to install and run [**ganache**](https://github.com/trufflesuite/ganache-cli) in background.
![ganache](https://truffleframework.com/tutorials/images/pet-shop/ganache-initial.png)
* After installing ganache and running in backgroud navigate to folder **migrations** and create a file named ```2_deploy_contracts.js``` and add the following code in it.[link](https://github.com/phunsukwangdu/ERC721-fullstack-Dapp-Tutorial/tree/master/migrations)
```javascript
var Tajmahal = artifacts.require("Tajmahal");
module.exports = function(deployer) {
deployer.deploy(Tajmahal);
}
```
* After following the above steps hit ```truffle migrate``` (make sure ganache is running in background).
* In Ganache, note that the state of the blockchain has changed. The blockchain now shows that the current block, previously 0, is now 4. In addition, while the first account originally had 100 ether, it is now lower, due to the transaction costs of migration.
![ganache](https://truffleframework.com/tutorials/images/pet-shop/ganache-migrated.png)
* Hola your contract is deployed on local blockchain!!! But we still have long way to go.
* Ok those following genuinely till here have a homework to do.Try testing smart contracts with truffle framework.
## Deploy smart contracts
Logicaly speaking there are tons of way to deploy smart contract on tons of network(ropsten,rinkbey,mainnet,private).We could
use truffle also to deploy our network.In this i will be discussing deployment of smart contracts on ropsten network.
* First we will be needing a wallet.Go and install chrome extension called Metamask.
* Once installed, you'll see the MetaMask fox icon next to your address bar. Click the icon and you'll see this screen appear:
![wallet](https://truffleframework.com/tutorials/images/pet-shop/metamask-privacy.png)
* Click Accept to accept the Privacy Notice.
* Then you'll see the Terms of Use. Read them, scrolling to the bottom, and then click Accept there too.
* ![wallet](https://truffleframework.com/tutorials/images/pet-shop/metamask-terms.png)
* Now you'll see the initial MetaMask screen. Set your password.
* ![wallet](https://truffleframework.com/tutorials/images/pet-shop/metamask-initial.png)
* Now we need to connect MetaMask to the blockchain.Connect to Ropsten network.
* ![wallet](https://cdn-images-1.medium.com/max/800/1*VFh3DPD30tJdPZl5WKqNmw.png)
* Create an Account
* ![wallet](https://cdn-images-1.medium.com/max/800/1*VVf3CVoA4z7bdoOT1Fqhuw.png)
* Copy Account Address
* ![wallet](https://cdn-images-1.medium.com/max/800/1*8VEep9up0Y40S6-yO_OlPw.png)
* Request Free ether from here or here. Paste the copied account address in text box and click on send me 1 test ether.
* ![wallet](https://cdn-images-1.medium.com/max/800/1*AjharO8gF4Xzr9ufy4iYLg.png)
* you got a ether !!!!
* ![wallet](https://cdn-images-1.medium.com/max/800/1*TxIvieOkIaRGDIv2ZMShYw.png)
* now, we have to the paste contracts in remix IDE [remix](http://remix.ethereum.org/)
* ![step11](https://github.com/phunsukwangdu/image/blob/master/step11.png)
* click on Run. Select Injected Web 3 Ropsten under environment and the account in Metamask is shown here under Account with balance ether as well.Hit the deploy button.
* ![step1](https://github.com/phunsukwangdu/image/blob/master/step1.png)
* Metamask will pop up with transaction details.
* ![step2](https://github.com/phunsukwangdu/image/blob/master/step3.png)
* Now enter the gass price.Higher you pay faster it gets executed.
* ![step3](https://github.com/phunsukwangdu/image/blob/master/step4.png)
* After transaction is completed you will be directed with etherscan link.
* ![step4](https://github.com/phunsukwangdu/image/blob/master/step5.png)
* Important ! please note down contract address and abi as they would be required for frontend integration.
## Frontend for smart contract and interaction with it.
Since we have made and deployed our smart contracts,we need to put a pretty face to it so that normal user can interact with it.
* Make a folder called __frontend__ in the directory.
* Make a file called __index.html__ in frontend folder and add the following code from [here](https://github.com/phunsukwangdu/ERC721-fullstack-Dapp-Tutorial/blob/master/frontend/index.html).
* You can add following Tajmahal images from [here](https://github.com/phunsukwangdu/ERC721-fullstack-Dapp-Tutorial/tree/master/frontend) to your frontend folder.
* ![frontend](https://github.com/phunsukwangdu/image/blob/master/cryptotajh.png)
* Now we have frontend in place,we need this frontend to interact with our smart contract.For this we require __web3js__
* ```<script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/web3.min.js"></script>``` code imports web3js in html file.
* Now lets ponder over following snippet in index.html file.
```javascript
<script>
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider);
} else {
// set the provide
没有合适的资源?快使用搜索试试~ 我知道了~
ERC721-fullstack-Dapp-Tutorial:一个ERC721 dapp教程,用于演示如何在区块链上表示和交易数...
共22个文件
json:5个
sol:5个
js:4个
需积分: 32 24 下载量 123 浏览量
2021-02-03
02:32:56
上传
评论 3
收藏 760KB ZIP 举报
温馨提示
让我们把泰姬陵出售! 是的,我并非没有理智,借助区块链技术完全有可能实现.Blockchian当然可以保护我们免受第三方干预。 我们将在稳固性的帮助下(通过编写智能合约)在区块链上构建数字资产(ERC721令牌),然后我们将使用IPFS部署Dapp。 设定环境 我们需要掌握松露,通过npm install -g truffle 。您还需要拥有Node.js v6 + LTS和npm(Node附带)以及Git。本教程最适合于Unix环境。 我们还需要ganache或testrpc进行本地部署。 让我们合谋出售泰姬陵 开放终端 使用mkdir tajmahal制作一个合适的文件夹,然后导航到cd tajmahal文件夹 现在使用truffle init初始化项目。 您会注意到合同迁移测试了truffle-config.js truffle.js目录和文件已添加到文件夹中。 合同/:包含我们智能合同的Solidity源文件。 这里有一个重要的合同,叫做Migrations.sol。 迁移/: Truffle使用迁移系统来处理智能合约部署。 迁移是附加的特殊智能合约,用于跟踪更改。
资源详情
资源评论
资源推荐
收起资源包目录
ERC721-fullstack-Dapp-Tutorial-master.zip (22个子文件)
ERC721-fullstack-Dapp-Tutorial-master
frontend
index.html 3KB
tajm.jpg 239KB
tajml.jpeg 8KB
tj.jpeg 155KB
tajmk.jpg 67KB
tajmm.jpg 161KB
taj.jpg 83KB
migrations
1_initial_migration.js 129B
2_deploy_contracts.js 115B
contracts
safemath.sol 1KB
erc721.sol 533B
ownable.sol 2KB
Tajmahal.sol 2KB
Migrations.sol 507B
build
contracts
Ownable.json 86KB
Migrations.json 52KB
Tajmahal.json 206KB
ERC721.json 44KB
SafeMath.json 92KB
truffle-config.js 545B
README.md 10KB
truffle.js 270B
共 22 条
- 1
YuanAndy
- 粉丝: 35
- 资源: 4491
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0