Hardhat and Foundry
The eSpace Testnet allows anyone to deploy a smart contract on eSpace. In this tutorial, you will learn how to deploy a contract on eSpace Testnet using common tools for developing on Ethereum. This demo repo illustrates contract deployment with Hardhat and Foundry.
Before you start deploying the contract, you need to request test tokens from a eSpace faucet.
Deploying smart contracts with Hardhat
-
Clone the repo and install dependencies:
git clone https://github.com/conflux-fans/espace-contract-guide
cd espace-contract-guide
yarn install -
Create a
.env
file following the example.env.example
in the root directory. ChangePRIVATE_KEY
to your own account private key in the.env
. -
Run
yarn compile
to compile the contract. -
Run
yarn deploy:eSpaceTestnet
to deploy the contract on the eSpace Testnet. -
Run
yarn test
for hardhat tests.
Video Guides
To learn more about smart contract deployment using Hardhat, please refer to the following videos:
- Hardhat Overview
- Hardhat Tutorial
Deploying smart contracts with Foundry
-
Clone the repo:
git clone https://github.com/conflux-fans/espace-contract-guide
cd espace-contract-guide -
Install Foundry:
curl -L https://foundry.paradigm.xyz | bash
foundryup -
Run
forge build
to build the project. -
Deploy your contract with Foundry:
forge create --rpc-url https://evmtestnet.confluxrpc.com \
--value <lock_amount> \
--constructor-args <unlock_time> \
--private-key <your_private_key> \
--legacy \
contracts/Lock.sol:Lock<lock_amount>
is the amount of testCFX
to be locked in the contract. Try setting this to some small amount, like0.0000001ether
. <unlock_time>
is the Unix timestamp after which the funds locked in the contract will become available for withdrawal. Try setting this to some Unix timestamp in the future, like1730390400
(this Unix timestamp corresponds to October 1, 2024).
Por ejemplo:
forge create --rpc-url https://evmtestnet.confluxrpc.com \
--value 0.00000000002ether \
--constructor-args 1696118400 \
--private-key 0xabc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1 \
--legacy contracts/Lock.sol:Lock
FAQs
Invalid parameters: tx
You may encounter error messages like Invalid parameters: tx
when deploying a contract. Please make sure that your deploy account has enough test tokens to deploy the contract. You can request test tokens from the eSpace faucet.
For more possible reasons, please refer to the Sending Transaction Errors and sendRawTransaction RPC method error messages
Feedback
Thank you for participating in and developing on the eSpace Testnet! If you encounter any issues, join our Discord and ask us in it.