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.
--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!
β π§ Result: [Function output here]
π View on Explorer: https://explorer.testnet.rootstock.io/address/0x4edd891c2e988e6145fe3e418c652ee33ebab9ae
- Check on Explorer**: You can also view the contract and interaction details on the Rootstock testnet explorer by following the link provided.
Interact with RSK bridge contractβ
The bridge command allows you to interact with the RSK bridge contract on the Rootstock blockchain. This command provides access to both read and write functions, enabling you to manage and query bridge contract data.
-
Read Functions: These are used to retrieve information from the RSK bridge contract.
-
Write Functions: These require user input and interaction to make changes or submit data to the contract.
Always be cautious when entering sensitive information, such as your wallet password.
Accessing the Bridge Commandβ
To start using the bridge command, open your terminal and use the following command:
- Mainnet
- Testnet
rsk-cli bridge
rsk-cli bridge --testnet
- Once you select either the Mainnet or Testnet, you will see the following message:
π§ Initializing bridge for testnet...
- You will then be prompted to choose the type of function you want to call:
? Select the type of function you want to call: (Use arrow keys)
β― read
write
- Selecting a Read Function
- Selecting a Write Function
- Use the arrow keys to highlight your choice and press Enter.
- If you select read, you will see a list of available read functions:
? Select a read function to call:
β― getBtcBlockchainBestChainHeight
getStateForBtcReleaseClient
getStateForDebugging
getBtcBlockchainInitialBlockHeight
getBtcBlockchainBlockHashAtDepth
getBtcTxHashProcessedHeight
isBtcTxHashAlreadyProcessed
- Use the arrow keys to choose the read function you want to use (e.g.,
getBtcBlockchainBestChainHeight
) and press Enter. - Response after executing a read function:
β
Function getBtcBlockchainBestChainHeight called successfully!
β π§ Result: 3500401
π View on Explorer: https://explorer.testnet.rootstock.io/address/0x0000000000000000000000000000000001000006
The result shows the output of the function, along with a link to view details on the blockchain explorer.
If you select write, you will be presented with a list of write functions:
? Select a write function to call: (Use arrow keys)
β― registerBtcTransaction
registerBtcCoinbaseTransaction
receiveHeader
Use the arrow keys to highlight your choice (e.g., registerBtcTransaction) and press Enter.
- Once a write function is selected, you will need to provide the required arguments:
- Enter the appropriate value for the tx argument and press Enter.
? Enter the value for argument tx (bytes):
- Enter the height value and press Enter.
? Enter the value for argument height (int256): 334
- Enter the pmt () value and press Enter.
? Enter the value for argument pmt (bytes): 345
To confirm the write operation, you will be prompted to enter your wallet password:
? Enter your password to decrypt the wallet: *****
Type your password and press Enter.
(bytes)
values should be in hexadecimal format and typically represent transaction or header data.(int256)
values should be whole numbers, such as block heights or transaction numbers.- Ensure valid data: Make sure any data you input aligns with the specific functionβs requirements and expected format to avoid errors.