Skip to content

Commit

Permalink
Update to new testnet Koi (#73)
Browse files Browse the repository at this point in the history
* Add new testnet information

* Update development node tutorial

* Update interact tutorials

* Update more places

* Update token transfer page

* Update evm tracing tutorial

* Disable unsupported staff

* Fix typo
  • Loading branch information
boundless-forest authored Jun 13, 2024
1 parent 3b6de14 commit bcf0853
Show file tree
Hide file tree
Showing 26 changed files with 341 additions and 263 deletions.
77 changes: 41 additions & 36 deletions docs/build/ethereum-tools/interact-with-ethersjs.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Overview

!!! note
Familiarity with Linux/Javascript is essential.

Similar to Web3.js, the [Ethers.js](https://docs.ethers.org/v5/) library offers a comprehensive suite of tools for interacting with Ethereum nodes using JavaScript. In addition, Darwinia provides an Ethereum-compatible API that supports JSON RPC invocations, making it fully compatible with the Ethers.js library. This compatibility enables developers to utilize the Ethers.js library to interact with a Darwinia node in a manner similar to interacting with an Ethereum node. This allows developers to leverage their existing knowledge and tools to build applications on the Darwinia network seamlessly.

## Prerequisites
Expand Down Expand Up @@ -36,16 +33,16 @@ In this tutorial, we will explore the usage of Ethers.js by deploying a contract
mkdir example-with-ethersjs && cd example-with-ethersjs && npm init --y
```

Install the Web3.js by runing the following command:
Install the ethers by running the following command:

```bash
npm install ethers@5.7.2
npm install ethers@6.13.0
```

## Contract Interaction

!!! note
The network provider used in this tutorial is the Pangolin Testnet. However, the concepts and techniques covered in this tutorial are applicable to other Darwinia networks as well.
The network provider used in this tutorial is the [Koi testnet](../getting-started/networks/koi.md). However, the concepts and techniques covered in this tutorial are applicable to other Darwinia networks as well.

### Prepare Contract

Expand Down Expand Up @@ -96,7 +93,7 @@ solc storage.sol --combined-json abi,bin,hashes --pretty-json > metadata.json

The output of `cat metadata.json`:

```json
```json title="metadata.json"
{
"contracts": {
"storage.sol:Storage": {
Expand Down Expand Up @@ -144,22 +141,22 @@ The output of `cat metadata.json`:
Create a deploy script by running this command:

```bash
node deploy.js
touch deploy.js
```

And paste the following content into it:

```jsx linenums="1" title="deploy.js"
const ethers = require("ethers");
const contractMetadata = require("../example-with-ethersjs/metadata.json");
const { ethers, JsonRpcProvider } = require("ethers");
const contractMetadata = require("./metadata.json");

// The test account
const accountFrom = {
address: "0x6Bc9543094D17f52CF6b419FB692797E48d275d0",
privateKey: "0xd5cef12c5641455ad949c3ce8f9056478eeda53dcbade335b06467e8d6b2accc",
}

const provider = new ethers.providers.JsonRpcProvider('https://pangolin-rpc.darwinia.network');
const provider = new JsonRpcProvider('https://koi-rpc.darwinia.network');
const wallet = new ethers.Wallet(accountFrom.privateKey, provider);
const abi = contractMetadata.contracts["storage.sol:Storage"].abi;
const bin = contractMetadata.contracts["storage.sol:Storage"].bin;
Expand All @@ -169,9 +166,10 @@ const deploy = async () => {

// Construct the contract instance
const contract = new ethers.ContractFactory(abi, bin, wallet);

let storage = await contract.deploy();
console.log(`Contract deployed at address: ${storage.address}`);
let address = await storage.getAddress();
console.log(`Contract deployed at address: ${address}`);
};

deploy();
Expand All @@ -187,7 +185,7 @@ The output like this:

```bash
Attempting to deploy from account 0x6Bc9543094D17f52CF6b419FB692797E48d275d0
Contract deployed at address: 0xE175242B7509e32a18973Ab622Ea3349a6C47429
Contract deployed at address: 0x24e263941c13bD12EEaAdba64531385e83103908
```

`0xE175242B7509e32a18973Ab622Ea3349a6C47429` is the address of the deployed storage contract, as a unique identifier for that contract. It will be used later to store and retrieve the number.
Expand All @@ -200,35 +198,39 @@ Create a store script by running this command:
touch store.js
```

Please paste the following content into the `store.js` file, *ensuring that you have updated the **`contractAddress`** in the script with the address of the contract you deployed.*
Please paste the following content into the `store.js` file.

!!! tip
Ensure that the `const contractAddress = '0x24e263941c13bD12EEaAdba64531385e83103908` in the script updated to your deployed contract.

```jsx linenums="1" title="store.js"
const ethers = require("ethers");
const contractMetadata = require("../example-with-ethersjs/metadata.json");
const { ethers, JsonRpcProvider } = require("ethers");
const contractMetadata = require("./metadata.json");

// The contract address deployed in last step
const contractAddress = "0x24e263941c13bD12EEaAdba64531385e83103908";

// The test account
const accountFrom = {
address: "0x6Bc9543094D17f52CF6b419FB692797E48d275d0",
privateKey: "0xd5cef12c5641455ad949c3ce8f9056478eeda53dcbade335b06467e8d6b2accc",
}

const provider = new ethers.providers.JsonRpcProvider('https://pangolin-rpc.darwinia.network');
address: "0x6Bc9543094D17f52CF6b419FB692797E48d275d0",
privateKey:
"0xd5cef12c5641455ad949c3ce8f9056478eeda53dcbade335b06467e8d6b2accc",
};
const provider = new JsonRpcProvider("https://koi-rpc.darwinia.network");
const wallet = new ethers.Wallet(accountFrom.privateKey, provider);
const abi = contractMetadata.contracts["storage.sol:Storage"].abi;

// The contract address deployed in last step
const contractAddress = '0xE175242B7509e32a18973Ab622Ea3349a6C47429';
const store = async () => {
// Construct the contract instance=
// Construct the contract instance
let storageContract = new ethers.Contract(contractAddress, abi, wallet);

// Call store to update the number to 3
let transaction = await storageContract.store(3);
let receipt = await transaction.wait();
console.log(`Tx successful with hash: ${receipt.transactionHash}`);
let transactionResponse = await storageContract.store(3);
console.log(`Tx successful with hash: ${transactionResponse.hash}`);
await transactionResponse.wait();
};

store();
store().catch(console.error);
```

Run the script by the command:
Expand All @@ -251,17 +253,20 @@ Create a retrieve script by running this command:
touch retrieve.js
```

Please paste the following content into the `retrieve.js` file, *ensuring that you have updated the **`contractAddress`** in the script with the address of the contract you deployed.*
Please paste the following content into the `retrieve.js` file.

```jsx linenums="1" title="retrieve.js"
const ethers = require("ethers");
const contractMetadata = require("../example-with-ethersjs/metadata.json");
!!! tip
Ensure that the `const contractAddress = '0x24e263941c13bD12EEaAdba64531385e83103908` in the script updated to your deployed contract.

const provider = new ethers.providers.JsonRpcProvider('https://pangolin-rpc.darwinia.network');
const abi = contractMetadata.contracts["storage.sol:Storage"].abi;
```jsx linenums="1" title="retrieve.js"
const { ethers, JsonRpcProvider } = require("ethers");
const contractMetadata = require("./metadata.json");

// The contract address deployed in last step
const contractAddress = '0xE175242B7509e32a18973Ab622Ea3349a6C47429';
const contractAddress = '0x24e263941c13bD12EEaAdba64531385e83103908';

const provider = new JsonRpcProvider('https://koi-rpc.darwinia.network');
const abi = contractMetadata.contracts["storage.sol:Storage"].abi;
const retrieve = async () => {
// Construct the contract instance
let storageContract = new ethers.Contract(contractAddress, abi, provider);
Expand Down
10 changes: 5 additions & 5 deletions docs/build/ethereum-tools/interact-with-foundry.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The four main tools in Foundry are:
- [Anvil](https://github.com/foundry-rs/foundry/blob/master/crates/anvil): Anvil is a local TestNet node that can be used for development purposes. It has the ability to fork preexisting networks.
- [Chisel](https://github.com/foundry-rs/foundry/blob/master/crates/chisel): Chisel is a Solidity REPL (Read-Eval-Print Loop) that allows for quick testing of Solidity snippets.

This guide will provide instructions on how to use Foundry's Forge and Cast tools to interact with Ethereum smart contracts on the Darwinia Pangolin TestNet.
This guide will provide instructions on how to use Foundry's Forge and Cast tools to interact with Ethereum smart contracts on the Darwinia [Koi TestNet](../getting-started/networks/koi.md).

## Prerequisites

Expand Down Expand Up @@ -43,7 +43,7 @@ In addition to these three folders, a git project will also be created along wit
## Contract Interaction

!!! note
The network provider used in this tutorial is the Pangolin Testnet. However, the concepts and techniques covered in this tutorial are applicable to other Darwinia networks as well.
The network provider used in this tutorial is the Koi Testnet. However, the concepts and techniques covered in this tutorial are applicable to other Darwinia networks as well.

### Prepare And Compile Contract

Expand Down Expand Up @@ -106,7 +106,7 @@ Compiler run successful!
Start the deployment by running the command:

```bash
forge create --rpc-url https://pangolin-rpc.darwinia.network --private-key 0xd5cef12c5641455ad949c3ce8f9056478eeda53dcbade335b06467e8d6b2accc src/storage.sol:Storage
forge create --rpc-url https://koi-rpc.darwinia.network --private-key 0xd5cef12c5641455ad949c3ce8f9056478eeda53dcbade335b06467e8d6b2accc src/storage.sol:Storage
```

The output like this:
Expand All @@ -126,7 +126,7 @@ Transaction hash: 0x8a9089e9aaf1569807cf3bae0f525370a490444fb6c55702aee46aaad70e
Run the command:

```bash
cast send --private-key 0xd5cef12c5641455ad949c3ce8f9056478eeda53dcbade335b06467e8d6b2accc --rpc-url https://pangolin-rpc.darwinia.network 0x0De784894D8FfE792EA7cF108E96f6e4451D066E "store(uint256)" 3
cast send --private-key 0xd5cef12c5641455ad949c3ce8f9056478eeda53dcbade335b06467e8d6b2accc --rpc-url https://koi-rpc.darwinia.network 0x0De784894D8FfE792EA7cF108E96f6e4451D066E "store(uint256)" 3
```

The output:
Expand All @@ -152,7 +152,7 @@ type 2
Run the command:

```bash
cast call 0x0De784894D8FfE792EA7cF108E96f6e4451D066E "retrieve()" --rpc-url https://pangolin-rpc.darwinia.network
cast call 0x0De784894D8FfE792EA7cF108E96f6e4451D066E "retrieve()" --rpc-url https://koi-rpc.darwinia.network
```

The output:
Expand Down
19 changes: 8 additions & 11 deletions docs/build/ethereum-tools/interact-with-hardhat.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Overview

!!! note
Familiarity with Linux/Javascript is essential.

[Hardhat](https://hardhat.org/) is a powerful Ethereum development environment designed to assist developers in managing and automating the repetitive tasks associated with building smart contracts and decentralized applications (DApps). Notably, Hardhat has the capability to directly interact with Darwinia's Ethereum API, enabling developers to deploy their smart contracts onto the Darwinia network. This compatibility allows developers to leverage Hardhat's features and tools when working with Darwinia, streamlining the development process and facilitating the creation of robust and reliable applications.

## Setting up a project
Expand Down Expand Up @@ -61,7 +58,7 @@ These are the default paths for a Hardhat project.
## Contract Interaction
!!! note
The network provider used in this tutorial is the Pangolin Testnet. However, the concepts and techniques covered in this tutorial are applicable to other Darwinia networks as well.
The network provider used in this tutorial is the [Koi Testnet](../getting-started/networks/koi.md). However, the concepts and techniques covered in this tutorial are applicable to other Darwinia networks as well.
### Prepare And Compile Contract
Expand Down Expand Up @@ -117,25 +114,25 @@ Compiled 1 Solidity file successfully
### Update Hardhat Config
Before working with the contracts, there are a few basic configurations that need to be set up. Replace the default **`hardhat.config`** file with the following content. This configuration includes the Pangolin network RPC information and adds a test account:
Before working with the contracts, there are a few basic configurations that need to be set up. Replace the default **`hardhat.config`** file with the following content. This configuration includes the Koi network RPC information and adds a test account:
```jsx linenums="1" title="hardhat.config"
require("@nomicfoundation/hardhat-toolbox");
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: "0.8.19",
defaultNetwork: "pangolin",
defaultNetwork: "koi",
networks: {
pangolin: {
url: "https://pangolin-rpc.darwinia.network",
koi: {
url: "https://koi-rpc.darwinia.network",
accounts: ["0xd5cef12c5641455ad949c3ce8f9056478eeda53dcbade335b06467e8d6b2accc"]
}
}
};
```
By updating the **`hardhat.config`** file with this content, you will have the necessary configurations in place to interact with the Pangolin network and use the test account for testing purposes.
By updating the **`hardhat.config`** file with this content, you will have the necessary configurations in place to interact with the Koi network and use the test account for testing purposes.
### Deploy Storage Contract
Expand All @@ -161,7 +158,7 @@ main().catch((error) => {
Start the deployment by running the command:
```jsx
npx hardhat run --network pangolin scripts/deploy.js
npx hardhat run --network koi scripts/deploy.js
```
The output like this:
Expand Down Expand Up @@ -209,7 +206,7 @@ ContractTransactionResponse {
_initializingPromise: [Promise],
provider: [BackwardsCompatibilityProviderAdapter]
},
_networkName: 'pangolin',
_networkName: 'koi',
_blockListeners: [],
_transactionHashListeners: Map(0) {},
_eventListeners: []
Expand Down
Loading

0 comments on commit bcf0853

Please sign in to comment.