Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update code snippets #344

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 网络端点 {: #network-endpoints }
## 网络端点 {: #network-endpoints }

Moonbase Alpha有两类端点供用户使用:HTTPS和WSS。

Expand All @@ -18,6 +18,7 @@ const Web3 = require('web3'); // Load Web3 library
// Create local Web3 instance - set Moonbase Alpha as provider
const web3 = new Web3('https://rpc.api.moonbase.moonbeam.network');
```

如果使用的是[Ethers.js库](/builders/build/eth-api/libraries/ethersjs){target=_blank},您可以使用`ethers.JsonRpcProvider(providerURL, {object})` 来定义开发者,并且将provider(提供者)URL设定至Moonbase Alpha:

```js
Expand All @@ -34,6 +35,6 @@ const provider = new ethers.JsonRpcProvider(providerURL, {

任何以太坊钱包都应当能够生成可以使用Moonbeam的地址(例如:[MetaMask](https://metamask.io/){target=_blank})。

## Chain ID {: #chain-id }
## Chain ID {: #chain-id }

Moonbase Alpha测试网的Chain ID为:`1287`,hex:`0x507`。
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ const Web3 = require('web3'); // Load Web3 library
.
.
// Create local Web3 instance - set Moonbeam as provider
const web3 = new Web3("RPC-API-ENDPOINT-HERE"); // Insert your RPC URL here
const web3 = new Web3('INSERT_RPC_API_ENDPOINT'); // Insert your RPC URL here
```

如果使用的是[Ethers.js库](/builders/build/eth-api/libraries/ethersjs){target=_blank},您可以使用`ethers.JsonRpcProvider(providerURL, {object})`来定义提供者,并且将提供者URL设定至Moonbeam:

```js
const ethers = require('ethers'); // Load Ethers library

const providerURL = "https://rpc.api.moonbeam.network";
const providerURL = 'INSERT_RPC_API_ENDPOINT';
// Define provider
const provider = new ethers.JsonRpcProvider(providerURL, {
chainId: 1284,
Expand All @@ -34,6 +34,6 @@ const provider = new ethers.JsonRpcProvider(providerURL, {

任何以太坊钱包都应当能够为Moonbeam生成有效地址(例如:[MetaMask](https://metamask.io/){target=_blank})。

## Chain ID {: #chain-id }
## Chain ID {: #chain-id }

Moonbeam的Chain ID为`1284`,hex为`0x504`。
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 网络端点 {: #network-endpoints }
## 网络端点 {: #network-endpoints }

Moonriver有两类端点供用户使用:HTTPS和WSS。

Expand All @@ -16,7 +16,7 @@ const Web3 = require('web3'); // Load Web3 library
.
.
// Create local Web3 instance - set Moonriver as provider
const web3 = new Web3("RPC-API-ENDPOINT-HERE"); // Insert your RPC URL here
const web3 = new Web3('INSERT_RPC_API_ENDPOINT'); // Insert your RPC URL here
```

如果使用的是[Ethers.js库](/builders/build/eth-api/libraries/ethersjs){target=_blank},您可以使用`ethers.JsonRpcProvider(providerURL, {object})` 来定义开发者,并且将provider(提供者)URL设定至Moonriver:
Expand All @@ -25,7 +25,7 @@ const web3 = new Web3("RPC-API-ENDPOINT-HERE"); // Insert your RPC URL here
const ethers = require('ethers'); // Load Ethers library


const providerURL = "RPC-API-ENDPOINT-HERE"; // Insert your RPC URL here
const providerURL = 'INSERT_RPC_API_ENDPOINT'; // Insert your RPC URL here
// Define provider
const provider = new ethers.JsonRpcProvider(providerURL, {
chainId: 1285,
Expand All @@ -35,6 +35,6 @@ const provider = new ethers.JsonRpcProvider(providerURL, {

任何以太坊钱包都应当能够生成可以使用Moonbeam的地址(例如:[MetaMask](https://metamask.io/){target=_blank})。

## Chain ID {: #chain-id }
## Chain ID {: #chain-id }

Moonriver的Chain ID为: `1285`,hex:`0x505`。
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
```js
struct Multilocation {
```solidity
struct Multilocation {
uint8 parents;
bytes[] interior;
}
Expand Down
18 changes: 5 additions & 13 deletions builders/build/eth-api/dev-env/brownie.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,8 @@ cd scripts && touch deploy.py
from brownie import Box, accounts

def main():
account = accounts.load('alice')
return Box.deploy(
{
'from': account,
'gas_limit': '200000'
}
)
account = accounts.load("alice")
return Box.deploy({"from": account, "gas_limit": "200000"})
```

您可以使用`run`命令并指定网络来部署`Box.sol`合约:
Expand Down Expand Up @@ -373,13 +368,10 @@ cd scripts && touch store-and-retrieve.py
from brownie import Box, accounts

def main():
account = accounts.load('alice')
account = accounts.load("alice")
box = Box[0]
store = box.store(5, {'from': accounts.load('alice'), 'gas_limit': '50000'})
retrieve = box.retrieve({'from': accounts.load('alice')})

print("Transaction hash for updating the stored value: " + store)
print("Stored value: " + retrieve)
store = box.store(5, {"from": accounts.load("alice"), "gas_limit": "50000"})
retrieve = box.retrieve({"from": accounts.load("alice")})
```

要运行脚本,您可以使用以下命令:
Expand Down
2 changes: 1 addition & 1 deletion builders/build/eth-api/dev-env/foundry.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ curl --data '{"method":"eth_blockNumber","params":[],"id":1,"jsonrpc":"2.0"}' -H
从这里,您可以将新合约部署到您的Moonbeam的分叉实例或与已部署的合约进行交互。在本教程的上述示例的基础上,您可以使用Cast进行调用,来检查您部署合约的帐户中铸造的MYTOK Token的余额:

```bash
cast call INSERT-CONTRACT-ADDRESS "balanceOf(address)(uint256)" INSERT-YOUR-ADDRESS --rpc-url http://localhost:8545
cast call INSERT_CONTRACT_ADDRESS "balanceOf(address)(uint256)" INSERT_YOUR_ADDRESS --rpc-url http://localhost:8545
```

## 使用Chisel {: #using-chisel }
Expand Down
67 changes: 33 additions & 34 deletions builders/build/eth-api/dev-env/hardhat.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,26 +211,26 @@ touch deploy.js
```js
// scripts/deploy.js
async function main() {
// 1. Get the contract to deploy
const Box = await ethers.getContractFactory('Box');
console.log('Deploying Box...');
// 1. Get the contract to deploy
const Box = await ethers.getContractFactory('Box');
console.log('Deploying Box...');

// 2. Instantiating a new Box smart contract
const box = await Box.deploy();
// 2. Instantiating a new Box smart contract
const box = await Box.deploy();

// 3. Waiting for the deployment to resolve
await box.waitForDeployment();
// 3. Waiting for the deployment to resolve
await box.waitForDeployment();

// 4. Use the contract instance to get the contract address
console.log('Box deployed to:', box.target);
// 4. Use the contract instance to get the contract address
console.log('Box deployed to:', box.target);
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
```

您现在可以使用`run`命令并指定`moonbase`作为网络来部署`Box.sol`合约:
Expand Down Expand Up @@ -272,7 +272,7 @@ npx hardhat console --network moonbase
3. 与此合约交互。在本示例中,您可以调用`store`方法并存储一个简单的值

```js
await box.store(5)
await box.store(5);
```

交易将通过您的Moonbase账户进行签署并传送至网络。后台输出将如下所示:
Expand Down Expand Up @@ -434,12 +434,12 @@ npx patch-package hardhat
```js
...
networks: {
hardhat: {
forking: {
url: "{{ networks.moonbeam.rpc_url }}",
}
}
}
hardhat: {
forking: {
url: '{{ networks.moonbeam.rpc_url }}',
},
},
},
...
```

Expand All @@ -448,12 +448,12 @@ npx patch-package hardhat
```js
...
networks: {
hardhat: {
forking: {
url: "{{ networks.moonriver.rpc_url }}",
}
}
}
hardhat: {
forking: {
url: '{{ networks.moonriver.rpc_url }}',
},
},
},
...
```

Expand All @@ -462,12 +462,12 @@ npx patch-package hardhat
```js
...
networks: {
hardhat: {
forking: {
url: "{{ networks.moonbase.rpc_url }}",
}
}
}
hardhat: {
forking: {
url: '{{ networks.moonbase.rpc_url }}',
},
},
},
...
```

Expand All @@ -494,7 +494,6 @@ async function main() {
const provider = new ethers.providers.StaticJsonRpcProvider(
'http://127.0.0.1:8545/'
);

const contract = new ethers.Contract(
'INSERT_CONTRACT_ADDRESS',
'INSERT_CONTRACT_ABI',
Expand Down
12 changes: 6 additions & 6 deletions builders/build/eth-api/dev-env/scaffold-eth.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,33 @@ yarn install
=== "Moonbeam"

```js
defaultNetwork = "moonbeam";
defaultNetwork = 'moonbeam';
```

=== "Moonriver"

```js
defaultNetwork = "moonriver";
defaultNetwork = 'moonriver';
```

=== "Moonbase Alpha"

```js
defaultNetwork = "moonbaseAlpha";
defaultNetwork = 'moonbaseAlpha';
```

=== "Moonbeam开发节点"

```js
defaultNetwork = "moonbeamDevNode";
defaultNetwork = 'moonbeamDevNode';
```

2. 在同一个文件的`module.exports/etherscan/apiKey`部分,为[Moonscan](https://moonscan.io/){target=_blank}添加API密钥,用于验证已部署的智能合约。了解如何生成Moonscan API密钥,请查看[Etherscan Plugins](/builders/build/eth-api/verify-contracts/etherscan-plugins/#generating-a-moonscan-api-key){target=_blank}部分。

3. (可选)在`function mnemonic()`部分,注释当网络未设置为`localhost`时控制台发出警告

```js
if (defaultNetwork !== "localhost") {
if (defaultNetwork !== 'localhost') {
//console.log(
// "☢️ WARNING: No mnemonic file created for a deploy account. Try `yarn run generate` and then `yarn run account`."
//);
Expand Down Expand Up @@ -205,7 +205,7 @@ yarn install
2. 在同一个文件`App.jsx`中,将`networkOptions`设置为您的DApp所支持的网络,例如:

```js
const networkOptions = [initialNetwork.name, "moonbeam", "moonriver"];
const networkOptions = [initialNetwork.name, 'moonbeam', 'moonriver'];
```

## 部署并启动DApp {: #deploy-and-launch-the-dapp }
Expand Down
Loading