dapps-solidity

ERC721トークンを作成してOpenSeaに掲載してみる – Dapps

OpenSeaにトークンを掲載する方法

OpenSeaのチュートリアルをやってみる。

OpenSea Developer Tutorial
Simple tutorial for a customizable marketplace for buying and selling on OpenSea

SUGGEST EDITS
Want an instant, customizable marketplace for your game items, collectibles, or other ERC-721 assets? You’ve come to the right place.

This tutorial will show you how to go from start to finish building a storefront for your items. We’ll walk you through structuring your ERC721 contract and off-chain metadata, viewing your items on OpenSea, and testing out the auction flow for your items.

By the end of this tutorial, you’ll know how to integrate with OpenSea and create a custom storefront for your items, just like the OpenSea Creature example storefront in this tutorial.

引用 https://docs.opensea.io/docs/1-structuring-your-smart-contract

OpenSeaCreatures ERC721 contracts
About OpenSeaCreatures.
This is a very simple sample ERC721 for the purposes of demonstrating integration with the OpenSea marketplace. We include a script for minting the items.

Additionally, this contract whitelists the proxy accounts of OpenSea users so that they are automatically able to trade the ERC721 item on OpenSea (without having to pay gas for an additional approval). On OpenSea, each user has a “proxy” account that they control, and is ultimately called by the exchange contracts to trade their items. (Note that this addition does not mean that OpenSea itself has access to the items, simply that the users can list them more easily if they wish to do so)

引用 https://github.com/ProjectOpenSea/opensea-creatures


$ truffle deploy  --network rinkeby
Using network 'rinkeby'.

Running migration: 1_initial_migrations.js
  Deploying Migrations...
  ... 0xe301680767e2d01...hash
  Migrations: 0x629598f...hash
Saving artifacts...
Running migration: 2_deploy_contracts.js
  Deploying Creature...
  ... 0xf540...hash
  Creature: 0x40098d....コントラクトのアドレス
Saving artifacts...

GitHubのReadmeはこうなってるけど

Minting tokens.

After deploying to the Rinkeby network, there will be a contract on Rinkeby that will be viewable on Rinkeby Etherscan. For example, here is a recently deployed contract. You should set this contract address and the address of your Metamask account as environment variables when running the minting script:


export OWNER_ADDRESS=""
export CONTRACT_ADDRESS=""
export NETWORK="rinkeby"
node scripts/mint.js

HDWalletProviderを指定する際に、アドレスのインデックスを指定しようとmint.jsを編集してたら
GitHubのReadmeと指定するべき環境変数が違ったので注意。

OWNER_ADDRESSはmint.jsで読み込んでますが
CONTRACT_ADDRESSは読み込まれておらず
NFT(ERC721)とFACTORY(ガチャ)の分岐があるので
今回はNFT(ERC721)なので、FACTORY_CONTRACT_ADDRESSを指定します。


const HDWalletProvider = require("truffle-hdwallet-provider")
const web3 = require('web3')
const MNEMONIC = process.env.MNEMONIC
const INFURA_KEY = process.env.INFURA_KEY
const FACTORY_CONTRACT_ADDRESS = process.env.FACTORY_CONTRACT_ADDRESS
const NFT_CONTRACT_ADDRESS = process.env.NFT_CONTRACT_ADDRESS
const OWNER_ADDRESS = process.env.OWNER_ADDRESS

途中省略
async function main() {
    const provider = new HDWalletProvider(MNEMONIC, `https://${NETWORK}.infura.io/${INFURA_KEY}` , 5 )
    const web3Instance = new web3(
        provider
    )


    if (NFT_CONTRACT_ADDRESS) {
        const nftContract = new web3Instance.eth.Contract(NFT_ABI, NFT_CONTRACT_ADDRESS, { gasLimit: "1000000" })

        // Creatures issued directly to the owner.
        for (var i = 0; i < NUM_CREATURES; i++) {
            const result = await nftContract.methods.mintTo(OWNER_ADDRESS).send({ from: OWNER_ADDRESS });
            console.log("Minted creature. Transaction: " + result.transactionHash)
        }
    } else if (FACTORY_CONTRACT_ADDRESS) {

NETWORKはすでにデプロイ時に反映済みなので
NFT_CONTRACT_ADDRESS、OWNER_ADDRESSを指定して実行しました。


$ export NFT_CONTRACT_ADDRESS="0x4006....デプロイしたContractのアドレス"
$ export OWNER_ADDRESS="0x01234...オーナーとするアドレス"
$ node scripts/mint.js
Minted creature. Transaction: 0xc90108641fa6b7...TxHash
Minted creature. Transaction: 0x52a54629d83812...TxHash
Minted creature. Transaction: 0x876160fee54a33...TxHash
Minted creature. Transaction: 0x500a341ec082c0...TxHash
Minted creature. Transaction: 0xc02abbbe93f762...TxHash

残高はあるのにtruffle deployで「Error encountered, bailing」- HDWalletProvider


Using network 'rinkeby'.

Running migration: 1_initial_migrations.js
  Deploying Migrations...
Error encountered, bailing. Network state unknown. Review successful transactions manually.
insufficient funds for gas * price + value

今回で言えばrinkebyの残高があるアドレスはMetamaskの5番目に生成したアドレスで
HDWalletProviderがそのアドレスを見ていなかったのが原因
HDWalletProviderに指定したいアドレスのindexを引き渡してあげる。


return new HDWalletProvider(
          MNEMONIC,
          "https://rinkeby.infura.io/" + INFURA_KEY
        , index );

opensea向けのDappsを作ろうと思ったらnpm installでエラー – gyp ERR! not ok

npm installで「gyp ERR! not ok」となってしまう。


gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp ERR! System Darwin 18.2.0
gyp ERR! command "/usr/local/Cellar/node/10.11.0/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/dp/src/Ethereum/opensea-creatures/node_modules/sha3
gyp ERR! node -v v10.11.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

package.jsonをみたらNodeのバージョンが高すぎるみたい。。


"engines": {
    "node": "8.11.x",
    "npm": "5.6.x"
  }

nodebrewを使ってるので、切り替えてOK


nodebrew install-binary v8.11.0
nodebrew use v8.11.0

web3.eth.sendSignedTransactionでエラー「 Uncaught (in promise) Error: Returned error: VM Exception while processing transaction: revert」

web3とethereumjs.TxでsendSignedTransactionをコントラクトに送ったところエラーが発生

Uncaught (in promise) Error: Returned error: VM Exception while processing transaction: revert

modifierなどの条件に引っかかっているだけだった。


require( コンディション );

requireは条件がfalseの場合にcontractの処理実行を停止して
contractの状態をトランザクション実行前に戻します。
そして、残ガスを呼び出し元に返却する。
requireは使った分のガスは消費されるので、注意。

truffle migrate でエラー「 Attempting to run transaction which calls a contract function, but recipient address is not a contract address」

TruffleでリモートのGanecheにコントラクトを配置しようとしたらエラーが発生

Error: Attempting to run transaction which calls a contract function, but recipient address 0x***** is not a contract address


dp$ truffle migrate --network development
Compiling ./contracts/TestToken.sol...
Compiling ./contracts/TestTokenCommons.sol...
Compiling openzeppelin-solidity/contracts/math/SafeMath.sol...
Writing artifacts to ./build/contracts

Using network 'development'.

Error: Attempting to run transaction which calls a contract function, but recipient address 0x**************************** is not a contract address
    at Object.InvalidResponse (/Users/dp/.nodebrew/node/v9.6.1/lib/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:38:1)

Ganecheをリセットしていたので、キャッシュ的なものがTruffleに残ってる?
削除すれば問題なくGanecheにコントラクトをデプロイできた。


rm -r build/contracts/