您当前的位置: 首页 > 

培根芝士

暂无认证

  • 0浏览

    0关注

    446博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

使用openZeppelin搭建ERC1155合约

培根芝士 发布时间:2022-01-06 20:28:18 ,浏览量:0

安装openZeppelin

npm install --save-dev @openzeppelin/contracts

创建一个truffle空项目

mkdir FishToken
cd FishToken
truffle init

在contracts目录下创建基于ERC1155的智能合约FishToken.sol

pragma solidity >=0.6.0  new HDWalletProvider(mnemonic, `https://rinkeby.infura.io/v3/{your infura project ID}`),
      network_id: 4,       // Ropsten's id
      gas: 5500000,        // Ropsten has a lower block limit than mainnet
      confirmations: 2,    // # of confs to wait between deployments. (default: 0)
      timeoutBlocks: 200,  // # of blocks before a deployment times out  (minimum/default: 50)
      skipDryRun: true     // Skip dry run before migrations? (default: false for public nets )
    },
  },
};
4、部署合约
truffle migrate --reset --network rinkeby
5、打开truffle控制台
truffle console --network rinkeby
6、执行测试
let account1 = "0xdfcB3D55462e20CF6B4f03881234689Ac8234BCD"
let account2 = "0xbe27d85f56558d4e01a7ae034567c7cf7e665555"
//获取实例
let instance = await FishToken.deployed()
//创建
await instance.reserveFish(1)
//查询余额
let balance = await instance.balanceOf(account1,1)
balance.toString()
//转账
instance.safeTransferFrom(account1, account2, 1, 1, "0x0")
//查询余额
balance = await instance.balanceOf(account2,1)
balance.toString()

在以太坊测试网络查看合约

https://rinkeby.etherscan.io/address/0x854320944cd1a9259477e284979e4e94cec571ae

查看交易

https://rinkeby.etherscan.io/tx/0x1522e8abf91ca03a15c23dc12a3b43382cb6ace35c71a06511e4650fd8884ca8

添加元数据Metadata
{
  "name": "Herbie Starbelly",
  "description": "Friendly OpenSea Creature that enjoys long swims in the ocean.",
  "image": "https://storage.googleapis.com/opensea-prod.appspot.com/creature/50.png",
  "attributes": [...]
}

ERC721和ERC1155合约中的每个token标识符都具有相应的元数据URI,该元数据URI返回有关该项目的其他重要信息,如该项目的名称、图像、描述等。

将元数据JSON保存为文件上传到服务器或者IPFS,将元数据URI配置到合约

//创建实例
let instance = await FishToken.deployed()
//设置URI
await instance.setURI("http://www.example.com/upload/{id}.json")
//获取URI
let uri = await instance.uri(1)
uri.toString()
在OpenSea上查看合约资产

Developer TutorialsThe largest peer-to-peer Non-Fungible Token marketplace. As the leading platform for Ethereum and Polygon NFT's, OpenSea prides itself in offering a first-in-class developer platform consisting of APIs, SDKs, and tutorials.https://docs.opensea.io/docsOpenSea有一个Rinkeby环境,允许开发人员测试他们与OpenSea的集成。

testnets.opensea.iohttps://testnets.opensea.io/导入合约资产

https://rinkeby.opensea.io/get-listed/step-twohttps://rinkeby.opensea.io/get-listed/step-two查看合约上创建的资产

https://testnets.opensea.io/assets//

校验合约项目的元数据 

https://testnets-api.opensea.io/asset///validate
关注
打赏
1660824269
查看更多评论
立即登录/注册

微信扫码登录

0.0399s