2018年 11月 の投稿一覧

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

npm installでエラー


npm install

Unhandled rejection Error: Command failed: /usr/local/bin/git submodule update -q --init --recursive
warning: templates not found in /var/folders/bv/0637g83s7bz_00000380000gn/T/pacote-git-template-tmp/git-clone-ea88f8b6
warning: templates not found in /var/folders/bv/0637g83s7bz_00000380000gn/T/pacote-git-template-tmp/git-clone-ea88f8b6
git-lfs smudge 'data/merkleTree.json': git-lfs: command not found
error: external filter 'git-lfs smudge %f' failed 127
error: external filter 'git-lfs smudge %f' failed
fatal: data/merkleTree.json: smudge filter lfs failed

brew install git-lfs
git lfs install

LogFormatを書き換え用と思ったら「Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.」でubuntoでmod_remoteip

ConohaVPSではアクセスIPはWAFのIPになります。
%{X-Forwarded-For}iを設定しようとしたら、注意文になにやらmod_remoteipを使えと。。


These deviate from the Common Log Format definitions in that they use %O
(the actual bytes sent including headers) instead of %b (the size of the requested file), because the latter makes it impossible to detect partial
requests.

#Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.
#Use mod_remoteip instead.
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

知らなかった。
昔から%{X-Forwarded-For}iを追加を何も考えずに設定していたので初めてmod_remoteipを設定してみる。


root@conoha-dev:~#apachectl configtest
AH00526: Syntax error on line 227 of /etc/apache2/apache2.conf:
Invalid command 'RemoteIPHeader', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.
root@conoha-dev:~#

あれ?モジュールがない?
a2enmodでモジュールをロードします。


root@conoha-dev:/etc/apache2# a2enmod remoteip
Enabling module remoteip.
To activate the new configuration, you need to run:
  systemctl restart apache2
root@conoha-dev:/etc/apache2# tree
├── mods-enabled
│   ├── access_compat.load -> ../mods-available/access_compat.load
│   ├── alias.conf -> ../mods-available/alias.conf
│   ├── alias.load -> ../mods-available/alias.load
│   ├── auth_basic.load -> ../mods-available/auth_basic.load
│   ├── authn_core.load -> ../mods-available/authn_core.load
│   ├── authn_file.load -> ../mods-available/authn_file.load
│   ├── authz_core.load -> ../mods-available/authz_core.load
│   ├── authz_host.load -> ../mods-available/authz_host.load
│   ├── authz_user.load -> ../mods-available/authz_user.load
│   ├── autoindex.conf -> ../mods-available/autoindex.conf
│   ├── autoindex.load -> ../mods-available/autoindex.load
│   ├── deflate.conf -> ../mods-available/deflate.conf
│   ├── deflate.load -> ../mods-available/deflate.load
│   ├── dir.conf -> ../mods-available/dir.conf
│   ├── dir.load -> ../mods-available/dir.load
│   ├── env.load -> ../mods-available/env.load
│   ├── filter.load -> ../mods-available/filter.load
│   ├── mime.conf -> ../mods-available/mime.conf
│   ├── mime.load -> ../mods-available/mime.load
│   ├── mpm_prefork.conf -> ../mods-available/mpm_prefork.conf
│   ├── mpm_prefork.load -> ../mods-available/mpm_prefork.load
│   ├── negotiation.conf -> ../mods-available/negotiation.conf
│   ├── negotiation.load -> ../mods-available/negotiation.load
│   ├── php7.2.conf -> ../mods-available/php7.2.conf
│   ├── php7.2.load -> ../mods-available/php7.2.load
│   ├── reqtimeout.conf -> ../mods-available/reqtimeout.conf
│   ├── reqtimeout.load -> ../mods-available/reqtimeout.load
│   ├── rewrite.load -> ../mods-available/rewrite.load
│   ├── setenvif.conf -> ../mods-available/setenvif.conf
│   ├── setenvif.load -> ../mods-available/setenvif.load
│   ├── socache_shmcb.load -> ../mods-available/socache_shmcb.load
│   ├── ssl.conf -> ../mods-available/ssl.conf
│   ├── ssl.load -> ../mods-available/ssl.load
│   ├── status.conf -> ../mods-available/status.conf
│   └── status.load -> ../mods-available/status.load
├── ports.conf

root@conoha-dev:/etc/apache2#apachectl configtest
Syntax OK
root@conoha-dev:/etc/apache2#

Cordova run が固まる Freeze on executing ‘cordova run’


Cordova run

がうんともすんとも言わなくなった。。
そんなときは「–verbose」をつけて確認してみる。


#cordova run  --verbose
  copy  www/node_modules/material-design-icons/image/2x_web/ic_filter_6_black_24dp.png platforms/android/assets/www/node_modules/material-design-icons/image/2x_web/ic_filter_6_black_24dp.png (new file)
  copy  www/node_modules/material-design-icons/image/2x_web/ic_filter_6_black_36dp.png platforms/android/assets/www/node_modules/material-design-icons/image/2x_web/ic_filter_6_black_36dp.png (new file)
  copy  www/node_modules/material-design-icons/image/2x_web/ic_filter_6_black_48dp.png platforms/android/assets/www/node_modules/material-design-icons/image/2x_web/ic_filter_6_black_48dp.png (new file)
  copy  www/node_modules/material-design-icons/image/2x_web/ic_filter_6_white_18dp.png platforms/android/assets/www/node_modules/material-design-icons/image/2x_web/ic_filter_6_white_18dp.png (new file)
  copy  www/node_modules/material-design-icons/image/2x_web/ic_filter_6_white_24dp.png platforms/android/assets/www/node_modules/material-design-icons/image/2x_web/ic_filter_6_white_24dp.png (new file)

ディレクトリ間違えててwwwディレクトリにアイコンセットをnpm installしてたみたいです。。
大量のコピーが走って固まってるように見えてただけでした。

LINEのタイムラインで流れてた多分詐欺サイト? – 現金スクラッチくじ引き大会はスクラッチを触ると「いいね」ボタンを押してしまう

LINEのタイムランで流れてきた詐欺?サイト
スクラッチを削るってところがキラキ●ウォーカー風だなと思って見てみたら、自分も「いいね」したことになっていて、HTMLをみてみたらLINEイイネのボタンがZ-index + 透明 + 全画面という昔Facebookいいねボタンで流行った手口になっていた。

LINE現金スクラッチくじ引き大会

スクラッチを削ろうとしてタップしたり、会社概要を探そうとタップすると
LINEいいねを押してしまう仕様になってる。

ただ、開いたブラウザでLINEログインしていないといけないのでFacebookよりは発動条件が厳しいようです。