Build and deploy smart contracts with CW3D
Instructions for how to use the smart contract backpack and deploy smart contracts with CW3D
Create-web3-dapp makes it easier to deploy and build your contracts, generating for you a number of shortcut scripts in the package.json file:
"build": "npx hardhat compile",
"deploy-testnet": "npx hardhat run ./scripts/MyContract_deploy.js --network YOUR_TESTNET",
"deploy": "npx hardhat run ./scripts/MyContract_deploy.js --network YOUR_MAINNET",
"node": "npx hardhat node",
"deploy-local": "npx hardhat run ./scripts/MyContract_deploy.js --network localhost"
- build: builds the smart contract created using the smart contract generating the artifacts folder
- deploy-testnet: will deploy you smart contract to the testnet of the chain specified during the setup process
- deploy: will deploy you smart contract to the chain specified during the setup process
- node: will spin up an hardhat local blockchain node to test your smart contracts
- deploy-local: will deploy your smart contract on the local blockchain node
All of these commands can be run inside the backend folder by prefixing them with "npm run". For example, to build your smart contract, run:
npm run build
Want to deploy on a local node?
To deploy locally, you'll need first to spin up your local node. Make sure to run:
npm run node
Before running:
npm run deploy-local
Let's see an example usage of the deployment scripts
Build and deploy smart contracts - example
While in the backend folder, run the following command in your terminal to build your contract:
npm run build
This will create the necessary files to deploy your contract on the chain.
To deploy your contract on chain, you'll have 3 choices:
If you have decided to include a testnet during the setup process, create-web3-dapp will also include a deployment script pointing to the right testnet.
To deploy your smart contract on the testnet, run the following command in your backend folder:
npm run deploy-testnet
If you haven't included a testnet, or if you're ready to deploy on the mainnet, run the following command:
npm run deploy
The third option is to deploy your contract on a local network. To do so run the following commands in sequence:
npm run node
npm run deploy-local
The first command will spin up a local development node that resembles the Ethereum mainnet. It will also spin up a number of wallets you'll be able to use to test your smart contract. The second command will deploy your contract on the local development node.
Now that we've learned how to build and deploy on the blockchain using the already implement Create Web3 Dapp scripts - it's time to start building your application using the React Components Marketplace.CLI.
Updated over 1 year ago