Setup Contract Development
Complete guide to set up your ink! development environment
Prerequisites
- Follow our quickstart guide to scaffold and set up your inkathon project.
Environment Setup
Install Rust and Cargo
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Install Pop CLI
Pop CLI provides an enhanced developer experience for working with ink! contracts:
cargo install --git https://github.com/r0gue-io/pop-cli.git --branch v6.0.0-alpha.1 --no-default-features --locked -F polkavm-contracts,chain,telemetry
ink! v6 Support
Make sure to install a v6-compatible version of Pop CLI from GitHub. If the command above is not working as expected, follow the official Pop CLI installation guide.
Run Pop CLI Setup Wizard
Pop CLI will take care of setting up your Rust environment for Polkadot development.
pop install
Local Node Setup
Optional
Install ink-node
Download and install the latest release from the ink-node
repository.
curl -L https://github.com/use-ink/ink-node/releases/latest/download/ink-node-mac-universal.tar.gz | tar xz
Make ink-node globally accessible
sudo mv ink-node /usr/local/bin/
Verify installation
ink-node --version
Build & Deploy Contracts
Start the Local Node
Optional
Open a separate terminal and run the local node in the background:
cd contracts
bun run node
The node will start at ws://127.0.0.1:9944
Build Contracts
In a new terminal, build the example contract:
cd contracts
# Build contracts
bun run build
# (Re-)generate Papi types
bun run codegen
Test Contracts
Run unit tests for your contracts to ensure they work correctly:
bun run test
Pop CLI Testing
The test script uses pop test
under the hood to run unit tests for all contracts in the /src
directory.
Deploy Contracts
Now you can deploy the contract to your local node:
CHAIN=dev bun run deploy
Deployer Account
//Alice
who is pre-funded on local nodes. You can overwrite this by either passing an ACCOUNT_URI
variable or defining an .env.<chain>
file (see environment).Configure Frontend
Update the frontend to connect to your local node (optional) and import the freshly deployed contract:
import { dev } from '@polkadot-api/descriptors'
// …
export const config = defineConfig({
chains: {
pop: {
descriptor: pop,
provider: getWsProvider('wss://rpc1.paseo.popnetwork.xyz'),
},
passethub: {
descriptor: passethub,
provider: getWsProvider('wss://testnet-passet-hub.polkadot.io'),
},
dev: {
descriptor: dev,
provider: getWsProvider('ws://127.0.0.1:9944'),
},
},
// …
})
import * as flipperDev from 'contracts/deployments/flipper/dev'
// …
export const flipper = {
contract: contracts.flipper,
evmAddresses: {
pop: flipperPop.evmAddress,
passethub: flipperPassethub.evmAddress,
dev: flipperDev.evmAddress,
},
ss58Addresses: {
pop: flipperPop.ss58Address,
passethub: flipperPassethub.ss58Address,
dev: flipperDev.ss58Address,
},
}
Start Frontend Development
Now you can already interact with your contract in the frontend.
# From project root
bun run dev
# Or run both frontend and node together
bun run dev-and-node
Visit http://localhost:3000 to see your dApp!