Utility repository for building and deploying smart contracts.
We will use deno, a modern alternative to Node that can work with TypeScript out of the box. You can install it by running:
curl -fsSL https://deno.land/install.sh | shIf you are unable to compile ink contracts and encounter the following issue:
error: panic_immediate_abort is now a real panic strategy!
please try using Rust toolchain version 1.91.1, as newer toolchains may trigger this issue due to changes in panic strategy handling.
We can now compile the contracts located in the contracts/ directory:
deno task build [--filter <contract-name>] [--clean]This does the following:
- Compile the bytecode for each contract into
codgen/bytecode/* - Generate the abi for each contract into
codgen/abi/*.tsand the indexcodegen/abis.ts
Update tools/deploy.ts to include new contracts you want to deploy.
Make sure to specify the constructor arguments and the value, if needed.
Once you have the chain running (see node-env), deploy the contracts by running:
deno task deploy [--filter <contract-name>]This command will update the codegen/addresses.ts file with the deployed contract addresses, so that you can easily reference them in your apps.
Note: You can also test against
geth, the deployment code will detect the chain and deploy the right bytecode (evm or pvm).
There is an example cli in the cli directory that you can run to interact with the deployed contracts.
./cli/playground.tsThe deployment scripts use the following environment variables:
PRIVATE_KEY: The private key of the account to deploy from (optional)RPC_URL: The RPC endpoint URL (optional, defaults tohttp://localhost:8545)
You can create a .env file in the project root to set these variables (see .env.example for a template).
If PRIVATE_KEY is not set, the default account 0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac will be used. This account is pre-funded at genesis on local chains.
For more information on setting up and deploying to different environments, check out the Polkadot Smart Contracts documentation.
For local development, you'll need to set up the node-env CLI to build and run the development node and Ethereum RPC proxy. See the node-env documentation for instructions.
Source scripts/node-env.sh for additional shell helpers not covered by the node-env CLI:
source scripts/node-env.shCast configuration — quickly set up cast for different environments:
cast_local # Local dev node
cast_westend # Westend Asset Hub
cast_testnet # Polkadot Hub TestNet (Paseo)
cast_kusama # Kusama Hub
cast_polkadot # Polkadot Hub
cast_is_pvm <address> # Check if contract is PVMDifferential testing with revive-differential-tests:
retester_test "complex/create/create2_many/test.json"
retester_ci --nodes 10 --threads 10- Asset Hub documentation to learn more about building Smart Contracts on Asset Hub.
- viem documentation to learn more about the library used to interact with EVM contracts.