Solidity
Reference
NFT作ってみる
tutorial
PUBLIC_KEY
means your wallet address
reference
doc
onlineIDE
output
created contract
created token
question
- when you mint a NFT at OpenSea, what smart contract is used?
- what contract is secure?
- for example, in the case of Web develop, we have to consider CSRF, XSS, etc...
こいつを使ってmintしてみる
-> mintするくらいならAPI使わなくてもできそうなので、フルスクラッチ開発でデプロイする
immutable X
basic
develop
reference
OpenSeaとの連携
予定はあるが、まだ未実施らしい
OpenSeaの対応は2021年11月現在まだ実現していませんが、Immutable Xの最新のウェブサイトにOpenSeaのロゴが掲載されていることから、今後OpenSeaがImmutable Xに対応する可能性はありそうです。
mint方法
目的
ユーザのmint前にこちらで画像を検証したい
以下を考慮して、こちらでmintする
ユーザがmint
- pros
- ユーザが気軽にmintしやすい
- cons
- イタズラで全く異なる画像をmintされる可能性がある
- 手数料がかかるのでほぼないと思うが、余地はなくしておきたい
- イタズラで全く異なる画像をmintされる可能性がある
こちらでmint
- pros
- イタズラを防げる
- cons
- ユーザが気軽にmintできない
- 先にmint時のgas feeを受け取るフローにすると、ユーザからすると持ち逃げのリスクがある
burnについて
- NFTのsmart contractにoptionalで
burn
のfunctionを実装することはできるが、make senseしない - 運営側が勝手にNFTをburnできる余地があるのは良くない
雑多に
- サーバ側でAPIキー的なの使って認証
- Ownableの活用
- 認証コードを画像に埋め込む?
- gas feeが気になるなら、Layer2などを使う?
- やっぱりETHが王道
理想フロー
- [ユーザ]こちらのサイト上でmintする
- [smart contract] mintNFT関数内で運営側に承認リクエストを飛ばす
- [運営] リクエストの内容を確認して、承認or否認
- [smart contract]
- if 承認
- mint処理を続行
- if 否認
- mint処理を中断
- ユーザに結果を通知
- if 承認
rinkeby使ってみる
contractのdeployでつまる
上記チュートリアルのropstenをrinkebyに書き換えると、以下のエラー発生
% npx hardhat run scripts/deploy.js --network rinkeby
ProviderError: Must be authenticated!
at HttpProvider.request (/PATH/node_modules/hardhat/src/internal/core/providers/http.ts:49:19)
at LocalAccountsProvider.request (/PATH/node_modules/hardhat/src/internal/core/providers/accounts.ts:187:34)
at GanacheGasMultiplierProvider._isGanache (/PATH/node_modules/hardhat/src/internal/core/providers/gas-providers.ts:315:30)
at GanacheGasMultiplierProvider.request (/PATH/node_modules/hardhat/src/internal/core/providers/gas-providers.ts:304:23)
at EthersProviderWrapper.send (/PATH/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)
at getSigners (/PATH/node_modules/@nomiclabs/hardhat-ethers/src/internal/helpers.ts:23:20)
at main (/PATH/scripts/deploy.js:2:22)
このページに基づき、hardhat.config.js
にgas
などを設定すると、以下のエラーが発生
% npx hardhat run scripts/deploy.js --network rinkeby
Deploying contracts with the account: 0xXXXXXXXXXXXX
Error: could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.5.1)
at Logger.makeError (PATH/node_modules/@ethersproject/logger/src.ts/index.ts:225:28)
at Logger.throwError (PATH/node_modules/@ethersproject/logger/src.ts/index.ts:237:20)
at EthersProviderWrapper.<anonymous> (PATH/node_modules/@ethersproject/providers/src.ts/json-rpc-provider.ts:403:23)
at step (PATH/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:48:23)
at Object.throw (PATH/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:29:53)
at rejected (PATH/node_modules/@ethersproject/providers/lib/json-rpc-provider.js:21:65)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
reason: 'could not detect network',
code: 'NETWORK_ERROR',
event: 'noNetwork'
}
これと同じ技術スタックのはずなのに動かない。。
質問サイトを使ってみる、rinkebyネット側の問題かも?
解決
- Alchemyでappを作成する際に、ENVIRONMENTで
DEVELOPMENT
を選択する
output
contract
token
opensea
ブラウザ上でmintする
reference
log
- 基本的に上記手順に沿って進める
- 上記手順では
ether.js
を使っているので、web3
に置き換える - webpack5の問題に詰まる
- https://stackoverflow.com/questions/70382479/error-library-web3-and-webpack-in-react-and-angular
-
A possible solution, for now, is to downgrade "react-scripts": "^4.0.3". At least that worked for me.
- 新しいcontractをdeploy
-
onlyOwener
のコントラクトメソッドを呼ぶためには、sign(署名)が必要-
signTransaction
,sendSignedTransaction
を使う
-
-
eth_sendTransaction
はalchemyでは使えない- https://docs.alchemy.com/alchemy/tutorials/sending-txs
-
eth_sendTransaction is used for sending unsigned transactions, which means the node you are sending to must manage your private key so it can sign the transaction before broadcasting it to the chain. Since Alchemy doesn't hold user's private keys, we do not support this method.
- web providerを使えばmintできた
- https://docs.alchemy.com/alchemy/documentation/alchemy-web3#with-a-browser-provider
- metamaskがsignをinjectしてくれる
-
ethereum.enable()
はdeprecatedなので、ethereum.request({ method: 'eth_requestAccounts' })
を使う必要がある- debug consoleでwarningが出ていた
- https://docs.metamask.io/guide/rpc-api.html#permissions
- typescript化には
typechain
が使える
output
- 27591174859c9d5f7129d665f7735f906f481a25
- このコミット時点のフロントソースコートが一番プレーンな状態
- 他にDApps作る時に使い回せるかも
contract
opensea
pinataにアップロード
Royalty
ref
※ロイヤリティは販売後は一旦OpenSea側に引かれ、2~4週間後にアカウントのウォレットに着金します
ロイヤリティの支払いは毎月、一度におこなわれます。
その際、どの支払い周期においても60ドル以上の手数料が累積した場合のみ支払いがおこなわれることに注意が必要です。
これにロイヤリティ回収のための独自の実装をいれるか、普及の可能性を持ったERC2981 に準拠したNFTだけが売買に際してロイヤリティの回収ができる可能性がある。
可能性があると言ったのは、たとえ対応しているNFTであっても、Metamaskなどのウォレットを使って個人間で直接NFTのやりとりをした場合には、NFT自身が売買金額を知る方法はなく、ロイヤリティの回収はできない。
現段階ではERC2981に準拠しているNFTは少なく、かつ、ERC2981 はあくまで売買プラットフォームに対してロイヤリティ額や率を伝えるだけのインターフェース。それ自体がロイヤリティフィーの回収まで行う仕組みではないからだ
Our ERC721 contract can't be made to have payable transferFrom
A reason why we did not make them payable in our implementation is to avoid funds getting stuck since there is no mechanism to withdraw any fund that might be sent by mistake
function safeTransferFrom(address _from, address _to, uint256 _tokenId) external payable;
-> enable to set payable
AuthenticatedProxy
対象となるNFT ContractのsafeTransferFromを実行するのが主な役割です。
set royalty (not work)
what I did
- copy OZ libs to your own
contracts
dir - change
safeTransferFrom
,transferFrom
to payable by myself - impl a function like following, and call it in above functions
- result purchase transaction
function _royalty() private {
uint256 rate = 10; // 10%
payable(owner()).transfer(msg.value.div(rate));
}
output
- it's difficult for smart contract to get royalty about trading on OpenSea
- OpenSea contract call
safeTransferFrom
of NFT contract,msg.value
= 0 in thesafeTransferFrom
? - according to below tx, OpenSea didn't intaract with NFT contract? any tx didn't appear on NFT contract when I tested buy a NFT
Manifold Studio
official
summary
- create NFT contract on GUI
- can set royalty to the contract
output
contract setting page
Sets default royalties for all tokens minted with this contract and can be updated at anytime. Royalty percentages are saved to the blockchain and can be split between as many accounts as you like. On OpenSea you must fill out the "Royalties" field in your Collection's setting to receive royalties from OpenSea sales! They do not respect on-chain royalties yet.
try
- set royalty
- call
setRoyalties
function according to below tx, but cannot see it in generated contract source code - https://rinkeby.etherscan.io/tx/0x45df52fa29f94352f1b40362d26403224a17bec356254930040c223cc0473427
- call
burn
- if owner burn a NFT, it's not shown up on OpenSea.
- ID of a burned NFT become missing number.
msg.sender
ContractでUserAからUserBにERC20 Tokenの送金を行う時は、approveでそのContractに権限を与えてからtransferFromする必要がある
UserA -> Contract -> ERC20の呼び出し関係になり、ECR20上のmsg.senderはContractになるから
tx.origin
duplicated
Upload source to Etherscan
ERC20 API: An Attack Vector on the Approve/TransferFrom Methods