Time to read: 1 min
Rootstock CLI | Interact with Verified Smart Contracts
The contract command allows you to interact with a verified smart contract on the Rootstock blockchain.
This command lists all available read-only functions within the contract, allowing you to call these functions to view data without altering the contract's state.
Parameters:
--address
: Specifies the address of the deployed contract on the blockchain. By providing the contract address,rsk-cli
knows which specific contract instance you want to interact with. This address uniquely identifies the contract on the network.--testnet
: Indicates that the command should be run on the RSK testnet instead of the mainnet. This parameter tells rsk-cli to execute the command on the testnet (the RSK network designated for testing purposes), which is useful for development and testing without using real funds or affecting production data.
To use this command:
- Mainnet
- Testnet
rsk-cli contract --address <address>
rsk-cli contract --address <address> --testnet
Replace <address\>
with the contract's address deployed, which is the one shown in the response of the deployed smart contract
This command will then display a list of all accessible read functions, making it easy to retrieve information from the contract.
Example command
rsk-cli contract --address 0x4edd891c2e988e6145fe3e418c652ee33ebab9ae --testnet
In this example:
0x4edd891c2e988e6145fe3e418c652ee33ebab9ae
is the address of the smart contract on the RSK testnet.- The
--testnet
flag ensures that the interaction occurs on the test network.
After running the command, you will see a response like this:
🔧 Initializing interaction on testnet...
🔎 Checking if contract 0x4edd891c2e988e6145fe3e418c652ee33ebab9ae is verified...
? Select a read function to call: (Use arrow keys)
❯ getContactInfo
name
phone
- Select a function to interact with: Use the arrow keys to navigate through the list of available read functions (e.g., getContactInfo, name, phone). Once you've highlighted the desired function, press Enter to select it.
For example, if you select name, you'll see:
? Select a read function to call: name
📜 You selected: name
- View the response**: After selecting a function, rsk-cli will call the function on the contract and display the result.
✅ Function name called successfully!