stylusguide
  • 1. Welcome to Arbitrum Stylus and Rust
    • Brief Introduction to Arbitrum Stylus
    • Importance of Rust in Blockchain Development
    • What You'll Learn in This Tutorial Series
  • 2. Setting Up Your Development Environment
    • Installing Rust
    • Setting Up Arbitrum Stylus
    • Basic Commands
  • 3. Your First Smart Contract: Hello World
    • Introduction to Smart Contracts
    • Writing the Hello World Contract
    • Deploying and Testing Your Contract
  • 4. Understanding Smart Contract Storage: Simple Storage
    • Basics of Contract Storage
    • Writing the Simple Storage Contract
    • Interacting with Storage Variables
  • 5. Creating Your Own Token: Token Contract
    • Introduction to Tokens and Standards
    • Writing the Token Contract
    • Deploying and Testing Your Token
  • 6. Additional Resources and Next Steps
Powered by GitBook
On this page
  • Step 4: Deploying the Contract
  • Step 5: Interacting with the Contract
  1. 3. Your First Smart Contract: Hello World

Deploying and Testing Your Contract

Step 4: Deploying the Contract

Check the Contract

Ensure the contract meets all requirements:

cargo stylus check --endpoint https://sepolia-rollup.arbitrum.io/rpc

Deploy the Contract

Ensure you have a valid private key saved in a file (e.g., private_key.txt). The file should contain only the private key without any extra characters or spaces.

Deploy the contract using the following command:

cargo stylus deploy --private-key-path=/path/to/private_key.txt --endpoint https://sepolia-rollup.arbitrum.io/rpc

Step 5: Interacting with the Contract

Setup MetaMask

Configure MetaMask for the Arbitrum network following these instructions.

Acquire Testnet ETH

Use faucets like BwareLabs or QuickNode to get Sepolia ETH for testing.

Interacting with the Contract using Ethers.js

const { ethers } = require("ethers");

const provider = new ethers.providers.JsonRpcProvider("https://sepolia-rollup.arbitrum.io/rpc");
const contractAddress = "<YOUR_CONTRACT_ADDRESS>";

const abi = [
    "function get_greeting() view returns (string)"
];

const privateKey = "<YOUR_PRIVATE_KEY>";
const wallet = new ethers.Wallet(privateKey, provider);
const contract = new ethers.Contract(contractAddress, abi, wallet);

async function main() {
    const greeting = await contract.get_greeting();
    console.log("Greeting from contract:", greeting);
}

main().catch(console.error);

By following these steps, you can set up your development environment, create and deploy a simple hello contract, and interact with it using Ethers.js.

PreviousWriting the Hello World ContractNext4. Understanding Smart Contract Storage: Simple Storage

Last updated 10 months ago