Q&A
現在以下の記事を参考に、ERC721の開発を試みています。
https://blog.opensphere.co.jp/posts/dapps003
●環境
vagrant - ubuntu
Hardhat(Solidity)
Openzeppelin
以下のコマンドでデプロイをしようとするとエラーが出るのですが、解決できません。
$ npx hardhat deploy --network online
**Error: ERROR processing /vagrant_data/testnft/deploy/MyERC721.ts:
TypeError: Cannot read property 'toString' of undefined**
at DeploymentsManager.onPendingTx (/vagrant_data/testnft/node_modules/hardhat-deploy/src/DeploymentsManager.ts:503:35)
at _deploy (/vagrant_data/testnft/node_modules/hardhat-deploy/src/helpers.ts:588:16)
at _deployOne (/vagrant_data/testnft/node_modules/hardhat-deploy/src/helpers.ts:768:16)
at Object.deploy [as func] (/vagrant_data/testnft/deploy/MyERC721.ts:19:22)
at DeploymentsManager.executeDeployScripts (/vagrant_data/testnft/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1049:22)
at DeploymentsManager.runDeploy (/vagrant_data/testnft/node_modules/hardhat-deploy/src/DeploymentsManager.ts:885:5)
at Environment._runTaskDefinition (/vagrant_data/testnft/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:14)
at Environment.run (/vagrant_data/testnft/node_modules/hardhat/src/internal/core/runtime-environment.ts:129:14)
at SimpleTaskDefinition.action (/vagrant_data/testnft/node_modules/hardhat-deploy/src/index.ts:528:32)
at Environment._runTaskDefinition (/vagrant_data/testnft/node_modules/hardhat/src/internal/core/runtime-environment.ts:217:14)
at DeploymentsManager.executeDeployScripts (/vagrant_data/testnft/node_modules/hardhat-deploy/src/DeploymentsManager.ts:1052:19)
関係するソースは以下の通りです。
contracts/MyERC721.sol
pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol"; contract OwnableDelegateProxy {} contract ProxyRegistry { mapping(address => OwnableDelegateProxy) public proxies; } contract MyERC721 is ERC721PresetMinterPauserAutoId { address proxyRegistryAddress; constructor( address _proxyRegistryAddress, string memory _name, string memory _symbol, string memory _baseTokenURI ) ERC721PresetMinterPauserAutoId(_name, _symbol, _baseTokenURI) { proxyRegistryAddress = _proxyRegistryAddress; } function isApprovedForAll(address _owner, address _operator) public override view returns (bool) { ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress); if (address(proxyRegistry.proxies(_owner)) == _operator) { return true; } return super.isApprovedForAll(_owner, _operator); } }
deploy/MyERC721.ts
import {HardhatRuntimeEnvironment} from 'hardhat/types'; import {DeployFunction} from 'hardhat-deploy/types'; import assert from "assert"; assert(process.env.PROXY_REGISTRY_ADDRESS); assert(process.env.TOKEN_NAME); assert(process.env.TOKEN_SYMBOL); assert(process.env.TOKEN_BASE_URI); const deploy: DeployFunction = async function ({ getNamedAccounts, deployments, getChainId, getUnnamedAccounts }: HardhatRuntimeEnvironment) { const { deploy, execute } = deployments; const { deployer } = await getNamedAccounts(); const MyERC721 = await deploy("MyERC721", { from: deployer, args: [process.env.PROXY_REGISTRY_ADDRESS, process.env.TOKEN_NAME, process.env.TOKEN_SYMBOL, process.env.TOKEN_BASE_URI], log: true, }) console.log('MyERC721: ' + MyERC721.address); await execute('MyERC721', {from: deployer}, 'mint', deployer); } export default deploy;
node_modules/hardhat-deploy/src/DeploymentsManager.ts
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types public async onPendingTx( tx: TransactionResponse, name?: string, // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types deployment?: any ): Promise<TransactionResponse> { if ( this.db.writeDeploymentsToFiles && this.network.saveDeployments && this.db.savePendingTx ) { const deployFolderPath = path.join( this.deploymentsPath, this.deploymentFolder() ); console.log("tx", tx.hash); const pendingTxPath = path.join(deployFolderPath, '.pendingTransactions'); fs.ensureDirSync(deployFolderPath); const rawTx = tx.raw; console.log(tx); const decoded = tx.raw ? undefined : { from: tx.from, gasPrice: tx.gasPrice.toString(), gasLimit: tx.gasLimit.toString(), to: tx.to, value: tx.value.toString(), nonce: tx.nonce, data: tx.data, r: tx.r, s: tx.s, v: tx.v, // creates: tx.creates, // TODO test chainId: tx.chainId, }; this.db.pendingTransactions[tx.hash] = name ? {name, deployment, rawTx, decoded} : {rawTx, decoded}; fs.writeFileSync( pendingTxPath, JSON.stringify(this.db.pendingTransactions, null, ' ') ); // await new Promise(r => setTimeout(r, 20000)); const wait = tx.wait.bind(tx); tx.wait = async () => { const receipt = await wait(); // console.log("checking pending tx..."); delete this.db.pendingTransactions[tx.hash]; if (Object.keys(this.db.pendingTransactions).length === 0) { fs.removeSync(pendingTxPath); } else { fs.writeFileSync( pendingTxPath, JSON.stringify(this.db.pendingTransactions, null, ' ') ); } return receipt; }; } return tx; }
恐らくDeploymentsManager.tsのonPendingTx関数内のtxが未定義なのだと思いますが、解決方法がわかりません。
よろしくお願いします。