Getting Started with Redstone Core
Getting Started with Redstone Core
Smart ContractsRedstone Core provides a framework for building decentralized applications (dApps) on the Redstone blockchain using Solidity smart contracts. This guide will walk you through the basics of setting up a development environment, creating a simple smart contract, and interacting with it on Redstone.## PrerequisitesBefore you can start building with Redstone Core, you'll need to have the following installed:- Node.js (version 14 or higher recommended) - npm package manager - Solidity compiler (version 0.8 or higher) - Redstone CLI tools - A code editor (Visual Studio Code recommended)## Setting Up the Development EnvironmentFirst, create a new project directory and initialize a Node.js project:
mkdir my-redstone-project
cd my-redstone-project
npm init
Next, install the Redstone CLI tools:
npm install -g @redstone-js/cli
This will provide access to commands like redstone-compile
and redstone-deploy
for interacting with Redstone.## Creating a Smart ContractIn your project, create a new SimpleStorage.sol
smart contract:
solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract SimpleStorage {
uint storedData;
function set(uint x) public {
storedData = x;
}
function get() public view returns (uint) {
return storedData;
}
}
This implements a simple contract for storing an unsigned integer value.## Compiling the Smart ContractTo compile the contract to Redstone bytecode, run:
redstone-compile SimpleStorage.sol
This will generate a SimpleStorage.cdc
file containing the compiled bytecode.## Deploying the Smart ContractTo deploy the contract to a local Redstone node, run:
redstone-deploy SimpleStorage.cdc
This will deploy the contract and print the deployment address.## Interacting with the Smart ContractTo call the smart contract functions, we can use the Redstone CLI. For example, to store the value 123:
redstone-execute <deploymentAddress> set(123) --signer <yourAccountAddress>
To read the stored value:
redstone-execute <deploymentAddress> get --signer <yourAccountAddress>
And that's it! You've deployed and interacted with a simple Redstone smart contract. From here you can start building more complex dApps.
Last updated