Skip to content

Conversation

@maxim-inj
Copy link
Collaborator

@maxim-inj maxim-inj commented Jun 15, 2025

Moved and distilled the changes from #11

Summary by CodeRabbit

  • New Features

    • Introduced a comprehensive ERC20 MTS workshop with detailed step-by-step instructions and supporting documentation.
    • Added scripts for deploying, minting, and querying ERC20 tokens, as well as interacting with WASM smart contracts on Injective.
    • Provided utility scripts for key management, balance checks, denomination queries, and contract deployment.
    • Included sample environment configuration and Makefile to streamline local development and testing.
  • Documentation

    • Added a README with an overview, prerequisites, and guided workshop steps for ERC20 MTS.
  • Chores

    • Updated .gitignore to exclude .DS_Store files.

@maxim-inj maxim-inj requested a review from arrivets June 15, 2025 04:25
@coderabbitai
Copy link

coderabbitai bot commented Jun 15, 2025

Walkthrough

A new ERC20 MTS workshop directory was introduced, containing scripts, configuration files, and documentation for deploying and interacting with ERC20 tokens and WASM contracts on the Injective blockchain. The additions include shell scripts for key management, contract deployment, balance queries, and token minting, along with a Rust source file defining CosmWasm contract message types. The .gitignore was updated to exclude .DS_Store files.

Changes

File(s) Change Summary
.gitignore Updated to ignore .DS_Store files.
workshops/erc20-mts/.local.env Added environment configuration for local development, including network URLs and user credentials.
workshops/erc20-mts/Makefile Added Makefile with targets for key import, contract deployment, minting, balance checks, and WASM deploy.
workshops/erc20-mts/README.md Added README with workshop overview, prerequisites, and step-by-step instructions.
workshops/erc20-mts/scripts/cli-*.sh Added shell scripts for Injective CLI operations (address, balances, denom, keys, queries, transactions).
workshops/erc20-mts/scripts/deploy-erc20*.sh Added scripts for deploying ERC20 contracts using Foundry tooling.
workshops/erc20-mts/scripts/deploy-wasm.sh Added script for deploying and instantiating a WASM contract on Injective.
workshops/erc20-mts/scripts/erc20-balance-*.sh Added scripts for querying ERC20 token balances for users.
workshops/erc20-mts/scripts/foundry-util.sh Added utility script with helper function for Foundry transaction result checking.
workshops/erc20-mts/scripts/import-*-key.sh Added scripts for importing user wallets into Cast and Injective CLI environments.
workshops/erc20-mts/scripts/mint-erc20.sh Added script for minting ERC20 tokens via contract call.
workshops/erc20-mts/scripts/wasm-query-counter.sh Added script to query WASM contract state (count and total funds).
workshops/erc20-mts/scripts/wasm-tx-increment.sh Added script to increment WASM contract counter with ERC20 tokens.
workshops/erc20-mts/wasm/counter_msg.rs Added Rust file defining CosmWasm contract message and response types for counter and IBC events.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI/Foundry
    participant Injective Node
    participant WASM Contract

    User->>CLI/Foundry: Run deployment/import/mint/balance script
    CLI/Foundry->>Injective Node: Send transaction or query (deploy, mint, query balance)
    Injective Node->>CLI/Foundry: Return result (contract address, balance, etc.)
    CLI/Foundry-->>User: Output result

    User->>CLI/Foundry: Deploy WASM contract
    CLI/Foundry->>Injective Node: Store and instantiate WASM contract
    Injective Node->>CLI/Foundry: Return code_id and contract address
    CLI/Foundry-->>User: Output WASM contract address

    User->>CLI/Foundry: Interact with WASM contract (increment/query)
    CLI/Foundry->>Injective Node: Execute/query WASM contract
    Injective Node->>WASM Contract: Handle execution/query
    WASM Contract-->>Injective Node: Return execution/query result
    Injective Node-->>CLI/Foundry: Return result
    CLI/Foundry-->>User: Output result
Loading

Poem

🐇
In a warren of scripts and code anew,
ERC20 hops where WASM contracts grew.
With keys imported, tokens mint and spin,
Balances checked, let the workshop begin!
Rusty messages for counters that climb—
Blockchain adventures, one shell at a time.
🥕

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@maxim-inj maxim-inj mentioned this pull request Jun 15, 2025
@maxim-inj maxim-inj self-assigned this Jun 15, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 31

🧹 Nitpick comments (26)
workshops/erc20-mts/scripts/import-cast-key.sh (1)

1-2: Validate required environment variables.
Add guards to fail fast if USER, USER_PWD, or USER_MNEMONIC are unset.

: "${USER:?Environment variable USER is required.}"
: "${USER_PWD:?Environment variable USER_PWD is required.}"
: "${USER_MNEMONIC:?Environment variable USER_MNEMONIC is required.}"
workshops/erc20-mts/scripts/cli-address.sh (1)

9-9: Use printf for consistent escape-sequence handling.
echo may not interpret backslashes portably.

- echo "\t* Injective address: $INJ_ADDRESS"
+ printf '\t* Injective address: %s\n' "$INJ_ADDRESS"

- echo "\t* Ethereum address: $ETH_ADDRESS"
+ printf '\t* Ethereum address: %s\n' "$ETH_ADDRESS"

Also applies to: 15-15

workshops/erc20-mts/scripts/cli-balances-user2.sh (1)

12-14: Use printf for newlines and consistent formatting.
echo "\n..." prints literal \n; switch to printf.

- echo "\n### RUNNING ###"
+ printf '\n### RUNNING ###\n'

- echo "###############\n"
+ printf '###############\n\n'
workshops/erc20-mts/scripts/cli-balances-user1.sh (1)

9-12: Use printf for formatting with newlines.
Replace echo "\n... with printf to handle escapes portably.

- echo "\n### RUNNING ###"
+ printf '\n### RUNNING ###\n'
...
- echo "###############\n"
+ printf '###############\n\n'
workshops/erc20-mts/README.md (2)

12-18: Use explicit markdown for numbered steps.
Consider adding a blank line before the list and ensuring the ordered list is consistently formatted for clarity.


19-22: Fix grammatical error in conclusion.
Change "We've created an ERC20 tokens" to "We've created an ERC20 token" to maintain singular agreement.

workshops/erc20-mts/scripts/erc20-balance-user2.sh (1)

12-14: Avoid literal \n in echo.
echo "\n### RUNNING ###" will print \n literally. Use printf or echo -e for newlines:

-echo "\n### RUNNING ###"
+printf "\n### RUNNING ###\n"
workshops/erc20-mts/scripts/cli-denom.sh (2)

15-19: Replace [[ ]] with POSIX checks.
[[ "$1" != erc20:* ]] is Bash-only. For POSIX compliance, use:

-if [[ "$1" != erc20:* ]]; then
-  echo "⚠️  Error: Denom must start with 'erc20:' prefix"
-  exit 1
-fi
+case "$1" in
+  erc20:*) ;;
+  *)
+    echo "⚠️  Error: Denom must start with 'erc20:' prefix"
+    exit 1
+    ;;
+esac
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 15-15: In POSIX sh, [[ ]] is undefined.

(SC3010)


21-27: Avoid printing literal newline escapes.
Use printf for formatted output instead of echo "\n...":

-echo "\n### QUERYING DENOM ###"
+printf "\n### QUERYING DENOM ###\n"
workshops/erc20-mts/scripts/wasm-query-counter.sh (2)

10-11: Avoid using the generic $USER variable.
Overwriting or relying on $USER can conflict with the shell’s username variable. Consider a more specific name (e.g., INJ_KEY_NAME) in .local.env.


14-21: Replace literal \n in echo statements.
Use printf for newlines to ensure correct formatting:

-echo "\n### QUERYING COUNT ###"
+printf "\n### QUERYING COUNT ###\n"
workshops/erc20-mts/scripts/deploy-erc20-mintburn.sh (2)

14-27: Print newlines portably
Plain echo won’t interpret \n by default. Use printf for consistent newline handling.

- echo "\n### RUNNING ###"
+ printf "\n### RUNNING ###\n"
...
- echo "###############\n"
+ printf "###############\n"

29-43: Improve error handling with set -e and remove manual checks
You perform explicit $? checks after forge create. Consider adding set -euo pipefail at the top to exit on any failure and drop the manual if [ $? -ne 0 ] block.

+# At top, after shebang:
+set -euo pipefail
workshops/erc20-mts/scripts/import-cli-key.sh (2)

7-10: Quote variables in external commands
Unquoted $USER and $USER_MNEMONIC may break if they contain spaces or special chars.

- if injectived keys list --keyring-backend=test | grep -q $USER; then
+ if injectived keys list --keyring-backend=test | grep -q "$USER"; then
...
-    echo "$USER_MNEMONIC" | injectived keys add $USER --recover --keyring-backend=test
+    echo "$USER_MNEMONIC" | injectived keys add "$USER" --recover --keyring-backend=test

17-28: Consider fail-fast on errors
This script lacks set -e. If any injectived call fails, the flow continues. Adding set -euo pipefail at the top will stop on errors and catch unset variables.

workshops/erc20-mts/scripts/mint-erc20.sh (2)

35-45: Use printf instead of literal \n in echo
To render new lines reliably, switch to printf.

- echo "\n### RUNNING ###"
+ printf "\n### RUNNING ###\n"
...
- echo "###############\n"
+ printf "###############\n"

47-56: Redundant manual exit due to set -e
You have set -e at the top, so the manual $? check after cast send is unnecessary. You can safely remove lines 56–59.

workshops/erc20-mts/scripts/deploy-erc20.sh (2)

8-21: Print commands with proper newlines
Replace echo "\n…" with printf for consistent newline rendering.

- echo "\n### RUNNING ###"
+ printf "\n### RUNNING ###\n"
...
- echo "###############\n"
+ printf "###############\n"

23-34: Consider set -euo pipefail and clean up error checks
Adding strict mode will automatically abort on failure, eliminating the need for manual exit code checks.

workshops/erc20-mts/scripts/erc20-balance-user1.sh (2)

19-21: Render newlines reliably
echo "\n…" won’t interpret \n. Prefer printf.

- echo "\n### RUNNING ###"
+ printf "\n### RUNNING ###\n"

20-21: Avoid quoting the pipe in echo
The literal | is quoted in the echo command and won’t reflect the actual pipeline. Remove the quotes around |.

- echo cast call $ERC20_ADDRESS "balanceOf(address)" $USER_ETH_ADDRESS "|" xargs cast decode-abi "balanceOf(address)(uint256)"
+ echo cast call "$ERC20_ADDRESS" "balanceOf(address)" "$USER_ETH_ADDRESS" | xargs cast decode-abi "balanceOf(address)(uint256)"
workshops/erc20-mts/scripts/deploy-wasm.sh (1)

10-22: echo "\n…" prints the literal “\n” – use printf for newlines

POSIX echo does not interpret back-slash escapes. Replace:

-echo "\n### RUNNING WASM STORE ###"
+printf '\n### RUNNING WASM STORE ###\n'

Same pattern for the other banner blocks to keep output readable across shells.

Also applies to: 45-51, 71-85, 110-116

workshops/erc20-mts/scripts/wasm-tx-increment.sh (2)

10-11: USER_INJ_ADDRESS is computed but never used

Drop it or use it; keeping unused vars clutters the script and misleads readers.

-USER_INJ_ADDRESS=$(injectived keys show $USER --keyring-backend=test -a)
+# USER_INJ_ADDRESS is available if you need to reference the sender later
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 10-10: USER_INJ_ADDRESS appears unused. Verify use (or export if used externally).

(SC2034)


13-17: Parameter validation: also verify ERC20 denom format

The usage string suggests <value>erc20:<contract_address>. A simple regex guard prevents malformed denominations:

if ! printf '%s\n' "$1" | grep -Eq '^[0-9]+erc20:[a-z0-9]{40,}$'; then
  echo "❌ Invalid denom format: $1"
  exit 1
fi
workshops/erc20-mts/wasm/counter_msg.rs (2)

37-49: Minor typo in documentation comment

Weather an ack is a successWhether an ack is a success.

-        /// Weather an ack is a success of failure according to the transfer spec
+        /// Whether an ack is a success or failure according to the transfer spec

18-23: Consider omitting Addr from query parameters for public state

Requiring the caller to supply an Addr for GetCount / GetTotalFunds is unusual when the contract can derive the address from env.message.sender (for execute) or simply maintain a global counter. If this is intentional (e.g., querying another user’s balance) ignore, otherwise rethink the API to keep queries minimal.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 55f96a7 and d8162ef.

⛔ Files ignored due to path filters (3)
  • .DS_Store is excluded by !**/.DS_Store
  • lib/.DS_Store is excluded by !**/.DS_Store
  • workshops/erc20-mts/wasm/counter.wasm is excluded by !**/*.wasm
📒 Files selected for processing (23)
  • .gitignore (1 hunks)
  • workshops/erc20-mts/.local.env (1 hunks)
  • workshops/erc20-mts/Makefile (1 hunks)
  • workshops/erc20-mts/README.md (1 hunks)
  • workshops/erc20-mts/scripts/cli-address.sh (1 hunks)
  • workshops/erc20-mts/scripts/cli-balances-user1.sh (1 hunks)
  • workshops/erc20-mts/scripts/cli-balances-user2.sh (1 hunks)
  • workshops/erc20-mts/scripts/cli-denom.sh (1 hunks)
  • workshops/erc20-mts/scripts/cli-keys.sh (1 hunks)
  • workshops/erc20-mts/scripts/cli-q.sh (1 hunks)
  • workshops/erc20-mts/scripts/cli-tx.sh (1 hunks)
  • workshops/erc20-mts/scripts/deploy-erc20-mintburn.sh (1 hunks)
  • workshops/erc20-mts/scripts/deploy-erc20.sh (1 hunks)
  • workshops/erc20-mts/scripts/deploy-wasm.sh (1 hunks)
  • workshops/erc20-mts/scripts/erc20-balance-user1.sh (1 hunks)
  • workshops/erc20-mts/scripts/erc20-balance-user2.sh (1 hunks)
  • workshops/erc20-mts/scripts/foundry-util.sh (1 hunks)
  • workshops/erc20-mts/scripts/import-cast-key.sh (1 hunks)
  • workshops/erc20-mts/scripts/import-cli-key.sh (1 hunks)
  • workshops/erc20-mts/scripts/mint-erc20.sh (1 hunks)
  • workshops/erc20-mts/scripts/wasm-query-counter.sh (1 hunks)
  • workshops/erc20-mts/scripts/wasm-tx-increment.sh (1 hunks)
  • workshops/erc20-mts/wasm/counter_msg.rs (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
workshops/erc20-mts/scripts/mint-erc20.sh (1)
workshops/erc20-mts/scripts/foundry-util.sh (1)
  • check_foundry_result (6-20)
workshops/erc20-mts/scripts/deploy-erc20-mintburn.sh (1)
workshops/erc20-mts/scripts/foundry-util.sh (1)
  • check_foundry_result (6-20)
workshops/erc20-mts/scripts/deploy-erc20.sh (1)
workshops/erc20-mts/scripts/foundry-util.sh (1)
  • check_foundry_result (6-20)
🪛 Shellcheck (0.10.0)
workshops/erc20-mts/scripts/cli-q.sh

[warning] 3-3: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)


[warning] 5-5: Use "$@" (with quotes) to prevent whitespace problems.

(SC2048)

workshops/erc20-mts/scripts/cli-tx.sh

[warning] 3-3: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)


[warning] 5-5: Use "$@" (with quotes) to prevent whitespace problems.

(SC2048)

workshops/erc20-mts/scripts/import-cast-key.sh

[warning] 3-3: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)

workshops/erc20-mts/scripts/cli-balances-user1.sh

[warning] 3-3: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)

workshops/erc20-mts/scripts/foundry-util.sh

[warning] 3-3: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)

workshops/erc20-mts/scripts/cli-keys.sh

[warning] 3-3: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)


[warning] 5-5: Use "$@" (with quotes) to prevent whitespace problems.

(SC2048)

workshops/erc20-mts/scripts/cli-balances-user2.sh

[warning] 3-3: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)

workshops/erc20-mts/scripts/wasm-query-counter.sh

[warning] 3-3: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)

workshops/erc20-mts/scripts/mint-erc20.sh

[warning] 5-5: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)


[warning] 6-6: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)

workshops/erc20-mts/scripts/cli-denom.sh

[warning] 5-5: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)


[warning] 15-15: In POSIX sh, [[ ]] is undefined.

(SC3010)

workshops/erc20-mts/scripts/erc20-balance-user2.sh

[warning] 3-3: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)

workshops/erc20-mts/scripts/deploy-erc20-mintburn.sh

[warning] 3-3: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)


[warning] 4-4: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)

workshops/erc20-mts/scripts/import-cli-key.sh

[warning] 3-3: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)

workshops/erc20-mts/scripts/erc20-balance-user1.sh

[warning] 3-3: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)

workshops/erc20-mts/scripts/deploy-erc20.sh

[warning] 3-3: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)


[warning] 4-4: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)

workshops/erc20-mts/scripts/deploy-wasm.sh

[warning] 3-3: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)

workshops/erc20-mts/scripts/wasm-tx-increment.sh

[warning] 3-3: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)


[warning] 10-10: USER_INJ_ADDRESS appears unused. Verify use (or export if used externally).

(SC2034)

🪛 checkmake (0.2.2)
workshops/erc20-mts/Makefile

[warning] 25-25: Missing required phony target "clean"

(minphony)


[warning] 25-25: Missing required phony target "test"

(minphony)

🔇 Additional comments (8)
.gitignore (1)

15-15: Ignore macOS system files

Adding .DS_Store prevents committing macOS finder metadata and keeps the repository clean.

workshops/erc20-mts/README.md (1)

1-9: README is clear and well-structured.
The workshop overview and prerequisites are concise, and the documentation links are accurate.

workshops/erc20-mts/scripts/deploy-erc20-mintburn.sh (1)

44-48: Deployment result parsing looks solid
You correctly validate the Foundry result and extract deployedTo. No further changes needed here.

workshops/erc20-mts/scripts/import-cli-key.sh (1)

18-27: Addressing key parsing and output
Retrieving and displaying both Injective and Ethereum addresses is clear and correct.

workshops/erc20-mts/scripts/mint-erc20.sh (1)

61-64: Mint logic and result validation are correct
The call to check_foundry_result and final status message align with expectations.

workshops/erc20-mts/scripts/deploy-erc20.sh (1)

38-42: Deployment result parsing is correct
Extracting and printing deployedTo via jq is implemented properly.

workshops/erc20-mts/scripts/erc20-balance-user1.sh (1)

23-26: Balance check logic is sound
You validate ERC20_ADDRESS and correctly decode the ABI-encoded balance.

workshops/erc20-mts/scripts/wasm-tx-increment.sh (1)

75-83: Guard against missing code field in tx result

jq -r '.code' returns null if the field is absent; comparison with "0" then fails. Safer:

TX_CODE=$(echo "$tx_result" | jq -r '.code // 0')

Comment on lines +13 to +15
USER=user1
USER_MNEMONIC="copper push brief egg scan entry inform record adjust fossil boss egg comic alien upon aspect dry avoid interest fury window hint race symptom"
USER_PWD=12345678
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Sensitive information committed

This file includes a full wallet mnemonic and password in version control. Remove .local.env from the repo, add it to .gitignore, and provide a template such as .local.env.example instead.

🤖 Prompt for AI Agents
In workshops/erc20-mts/.local.env around lines 13 to 15, sensitive information
like the wallet mnemonic and password is committed to version control. Remove
the .local.env file from the repository, add .local.env to the .gitignore file
to prevent future commits, and create a .local.env.example template file with
placeholder values for users to fill in their own credentials.

@@ -0,0 +1,20 @@
#!/bin/sh

source .local.env
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use POSIX-compatible sourcing

In POSIX sh, source is undefined. Replace it with dot sourcing:

- source .local.env
+ . .local.env
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 3-3: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)

🤖 Prompt for AI Agents
In workshops/erc20-mts/scripts/foundry-util.sh at line 3, replace the use of
'source .local.env' with '. .local.env' to ensure POSIX-compatible sourcing, as
'source' is not defined in POSIX sh.

@@ -0,0 +1,7 @@
#!/bin/sh

source .local.env
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use POSIX-compatible sourcing

Replace source .local.env with:

- source .local.env
+ . .local.env
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
source .local.env
. .local.env
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 3-3: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)

🤖 Prompt for AI Agents
In workshops/erc20-mts/scripts/cli-q.sh at line 3, replace the non-POSIX `source
.local.env` command with the POSIX-compatible `. .local.env` syntax to ensure
the script runs correctly in all POSIX-compliant shells.


source .local.env

injectived q $* --node $INJ_URL
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Quote positional parameters

Use "$@" instead of $* to preserve arguments with spaces, and quote $INJ_URL:

- injectived q $* --node $INJ_URL
+ injectived q "$@" --node "$INJ_URL"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
injectived q $* --node $INJ_URL
injectived q "$@" --node "$INJ_URL"
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 5-5: Use "$@" (with quotes) to prevent whitespace problems.

(SC2048)

🤖 Prompt for AI Agents
In workshops/erc20-mts/scripts/cli-q.sh at line 5, replace the unquoted
positional parameters $* with "$@" to correctly preserve arguments containing
spaces, and also quote the $INJ_URL variable to handle any spaces or special
characters safely. This ensures all arguments are passed accurately to the
injectived command.

@@ -0,0 +1,7 @@
#!/bin/sh

source .local.env
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use POSIX-compatible sourcing

Replace source .local.env with:

- source .local.env
+ . .local.env
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 3-3: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)

🤖 Prompt for AI Agents
In workshops/erc20-mts/scripts/cli-tx.sh at line 3, replace the
non-POSIX-compliant `source .local.env` command with the POSIX-compatible `.
.local.env` syntax to ensure compatibility across different shell environments.

Comment on lines +63 to +68
store_res=$tx_result

# Extract code ID from transaction response
CODE_ID=$(echo $store_res | jq -r '.events[] | select(.type=="store_code") | .attributes[] | select(.key=="code_id") | .value')
echo "Contract Code ID: $CODE_ID"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Gracefully abort when CODE_ID / CONTRACT_ADDRESS is empty

If jq fails to locate the attribute the variables become empty strings, leading to confusing downstream errors. Add a guard:

if [ -z "$CODE_ID" ]; then
  echo "❌ Unable to extract code_id from transaction."
  exit 1
fi

Repeat for CONTRACT_ADDRESS.

Also applies to: 130-133

🤖 Prompt for AI Agents
In workshops/erc20-mts/scripts/deploy-wasm.sh around lines 63 to 68, add a check
after extracting CODE_ID to verify if it is empty. If CODE_ID is empty, print an
error message and exit the script with a non-zero status to prevent confusing
downstream errors. Similarly, add the same kind of check for CONTRACT_ADDRESS
around lines 130 to 133 to ensure the script aborts gracefully if
CONTRACT_ADDRESS is not found.

Comment on lines +1 to +4
#!/bin/sh

source .local.env

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Shebang & sourcing are inconsistent – decide on Bash or strict POSIX

source is a Bash-ism but the shebang points to /bin/sh. Either:

-#!/bin/sh
-source .local.env
+#!/usr/bin/env bash
+set -euo pipefail
+. .local.env   # POSIX-portable “source”

or make the script strictly POSIX (. instead of source, avoid Bash-only flags).
Fail-fast flags (set -euo pipefail) are strongly recommended.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#!/bin/sh
source .local.env
#!/usr/bin/env bash
set -euo pipefail
. .local.env # POSIX-portable “source”
# …rest of your script…
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 3-3: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)

🤖 Prompt for AI Agents
In workshops/erc20-mts/scripts/deploy-wasm.sh at lines 1 to 4, the script uses a
shebang for /bin/sh but employs the Bash-specific 'source' command. To fix this,
either change the shebang to /bin/bash to match the use of 'source', or replace
'source' with the POSIX-compliant '.' command and avoid any Bash-only features.
Additionally, add fail-fast flags like 'set -euo pipefail' near the top of the
script to improve robustness.

Comment on lines +8 to +9
USER_ADDRESS=$(injectived keys show $USER --keyring-backend=test -a)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Quote variable expansions to avoid word-splitting & injection

Examples:

-USER_ADDRESS=$(injectived keys show $USER --keyring-backend=test -a)
+USER_ADDRESS=$(injectived keys show "$USER" --keyring-backend=test -a)

Apply the same to every $USER, $CHAIN_ID, $INJ_URL, $CODE_ID, $TXHASH, etc.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
USER_ADDRESS=$(injectived keys show $USER --keyring-backend=test -a)
USER_ADDRESS=$(injectived keys show "$USER" --keyring-backend=test -a)
🤖 Prompt for AI Agents
In workshops/erc20-mts/scripts/deploy-wasm.sh around lines 8 to 9, variable
expansions like $USER should be quoted to prevent word-splitting and potential
injection issues. Update all instances of variables such as $USER, $CHAIN_ID,
$INJ_URL, $CODE_ID, $TXHASH, etc., by enclosing them in double quotes, for
example, change $USER to "$USER".

Comment on lines +21 to +34
echo "\n### EXECUTING INCREMENT ###"
echo injectived tx wasm execute $WASM_CONTRACT '{"increment":{}}' \
--amount $1 \
--from $USER \
--chain-id $CHAIN_ID \
--node $INJ_URL \
--gas-prices 500000000inj \
--gas auto \
--gas-adjustment 1.3 \
--broadcast-mode sync \
--keyring-backend test \
--output json \
-y
echo "########################\n"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Quote variable expansions & use printf instead of echo "\n"

Same concerns as in deploy-wasm.sh. Quote $WASM_CONTRACT, $USER, $CHAIN_ID, $INJ_URL, and $1. Replace banner echoes with printf.

Also applies to: 36-46, 58-63

🤖 Prompt for AI Agents
In workshops/erc20-mts/scripts/wasm-tx-increment.sh around lines 21 to 34, the
variable expansions like $WASM_CONTRACT, $USER, $CHAIN_ID, $INJ_URL, and $1 are
unquoted which can cause word splitting or globbing issues. Quote all these
variables to ensure safe expansion. Also, replace echo statements that print
newlines (e.g., echo "\n### EXECUTING INCREMENT ###") with printf commands for
consistent and portable newline handling. Apply the same quoting and printf
replacements to lines 36-46 and 58-63 as well.

Comment on lines +1 to +4
#!/bin/sh

source .local.env

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Same Bash / POSIX mismatch & missing fail-fast flags

See previous script: pick Bash or pure POSIX. If Bash is fine:

-#!/bin/sh
-source .local.env
+#!/usr/bin/env bash
+set -euo pipefail
+. .local.env
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#!/bin/sh
source .local.env
#!/usr/bin/env bash
set -euo pipefail
. .local.env
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 3-3: In POSIX sh, 'source' in place of '.' is undefined.

(SC3046)

🤖 Prompt for AI Agents
In workshops/erc20-mts/scripts/wasm-tx-increment.sh at lines 1 to 4, the script
uses a shebang for sh but may include Bash-specific syntax, causing POSIX
compatibility issues. Decide whether to use Bash or pure POSIX shell. If Bash is
acceptable, change the shebang to #!/bin/bash and add fail-fast flags like set
-euo pipefail at the start to ensure the script exits on errors and undefined
variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants