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.

Last updated