deploy.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/bash
  2. # This script compiles Rust contracts to WebAssembly and deploys the .wasm binaries to a blockchain using `cargo stylus deploy`.
  3. # It retrieves crate names from Cargo.toml files in the examples directory and automates the deployment process for each contract.
  4. set -e
  5. mydir=$(dirname "$0")
  6. cd "$mydir" || exit
  7. cd ..
  8. export RPC_URL=http://localhost:8547
  9. export PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
  10. export WALLER_ADDRESS=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
  11. cd "nitro-testnode"
  12. ./test-node.bash script send-l2 --to address_$WALLER_ADDRESS --ethamount 0.1
  13. cd ..
  14. # Check contract wasm binary by crate name
  15. deploy_wasm () {
  16. local CONTRACT_CRATE_NAME=$1
  17. local CONTRACT_BIN_NAME="${CONTRACT_CRATE_NAME//-/_}.wasm"
  18. echo "deploy contract $CONTRACT_CRATE_NAME"
  19. cargo stylus deploy --wasm-file ./target/wasm32-unknown-unknown/release/"$CONTRACT_BIN_NAME" \
  20. --endpoint $RPC_URL \
  21. --private-key $PRIVATE_KEY \
  22. --no-verify
  23. }
  24. # Retrieve all alphanumeric contract's crate names in `./examples` directory.
  25. get_example_crate_names () {
  26. # shellcheck disable=SC2038
  27. # NOTE: optimistically relying on the 'name = ' string at Cargo.toml file
  28. find ./examples -maxdepth 2 -type f -name "Cargo.toml" | xargs grep 'name = ' | grep -oE '".*"' | tr -d "'\""
  29. }
  30. NIGHTLY_TOOLCHAIN=${NIGHTLY_TOOLCHAIN:-nightly-2024-09-05}
  31. cargo +"$NIGHTLY_TOOLCHAIN" build --release --target wasm32-unknown-unknown -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort
  32. for CRATE_NAME in $(get_example_crate_names)
  33. do
  34. deploy_wasm "$CRATE_NAME"
  35. done