For the complete documentation index, see llms.txt. This page is also available as Markdown.

Foundry

This section will guide smart contracts development on Viction network using Foundry tool.

Prerequisites

Before you begin, ensure you've:

  • Download Rust.

  • An ethereum wallet.

  • Funded your wallet for caring gas fee of transactions.

Installations

You will need the Rust compiler and Cargo, the Rust package manager. Install both with command:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Foundry generally only supports building on the latest stable Rust version. If you have an older Rust version, you can update with rustup:

rustup update stable

Install Foundryup:

curl -L https://foundry.paradigm.xyz | bash

Install Foundry:

foundryup

Creating a Foundry Project

Run following commands:

Configurations

We will need some configs in the foundry.toml to work with Viction network.

Load environment variables

Setup .env file:

Substitute <YOUR_PRIVATE_KEY> with the private key for your wallet.

Note: Requires prefixing with 0x.

Compile the smart contract

In a Foundry project, contracts will be placed at the src/ folder. Create a simple token contract MyToken.sol for example:

The Solidity code above defines a smart contract named MyToken. The code uses the ERC20 interface provided by the OpenZeppelin Contracts library to create a token smart contract. OpenZeppelin allows developers to leverage battle-tested smart contract implementations that adhere to official ERC standards.

To add the OpenZeppelin Contracts library to your project, run:

The Openzeppelin Contracts library is already in the lib/openzeppelin-contracts folder. In order to simple import contracts with alias @openzeppelin/contracts, add remappings to assign the library directiory with the alias in foundry.toml:

To compile ERC20 contract, run:

Deploy the smart contract​

Once your contract has been successfully compiled, you can deploy the contract to the Viction networks.

To deploy the contract to the Viction mainnet, you'll need to add the script/MyToken.s.sol in the project:

Finally, ensure your wallet has enough fund to cover gas fee and run script with command:

Note:

  • Deployment requires flag --legacy because the Viction RPC currently not supported EIP-1559 transactions. Reference.

The transaction informations will appear after running script likes this:

We got the success deployment with txnHash is 0x3e2ff561e92a99e35cbd72ec707ae7642d2a87ef9c3213afbfc9544f37ee8b8f and the MyToken contract address is 0xC9a8D9CEa9bF2450ED8082d73e8DaFC47989558E. We can check its on VicScan.

Verify contract on VicScan

The first, we need to create a json file that contains arguments of contructor when deploy contract. File path: ./script/arguments.json:

Run below commands to verify contract on VicScan:

  • For mainnet:

  • For testnet:

The successful verification will show:

Last updated