基于区块链的毕业设计ethermint-simple-smart-contract – ethermint简单智能合约

本文提供基于区块链的毕业设计国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,基于区块链的毕业设计ethermint-simple-smart-contract – ethermint简单智能合约 是一篇很好的国外资料

ethermint-simple-smart-contract

ethermint-simple-smart-contract is an exercise to deploy a simple smart contract with Ethermint.

It includes running an ethermint node, deploying a local ERC20 token smart contract and writing a client-side program to query and transfer token balances on the deployed smart contract.

For more information on ethermint, please refer to the ethermint documentation

  • ethermint-simple-smart-contract
    • Getting Started
      • Prerequisites
      • Installation
    • Usage
      • Deploy contracts
      • Run Tests
      • Interact with the contract
      • Adding a new contracts
    • Observations

Getting Started

The project’s architecture consists of a client and an Ethermintd node. The Ethermintd node represents the EVM blockchain that the client can interact with. The client deploys/migrates contracts on the blockchain in order for them to be available to users of the Ethermint network. Once a contract is deployed to the network the client allows you to interact with that contract.

You can use frameworks like Truffle or Hardhat to 1) define smart contracts, 2) connect to the node network using the network config, 3) deploy contracts, 4) run tests and 5) interact with the deployed contract. I considered the following implementation options:

  • Truffle: Deploy contract with truffle migrate --network development or use ethers.js/web3.js to deploy and interact with contract
  • Hardhat: Deploy and interact with contracts
  • Geth: Interact with deployed contract using the geth console

Prerequisites

  • Node/Deno and npm/yarn
  • jq
  • Go 1.16+
  • JavaScript/TypeScript: web3.js
  • truffle 5.1.44

Installation

  1. Install npm packages (e.g. solidity linter solhint):

    $ npm install 
  2. Setup and start a local Ethermintd node following the instructions in the Ethermint docs. Before starting the node, set the client config to run a local testnet:

    { "chain-id": "ethermint_9000-1", "keyring-backend": "test", "output": "text", "node": "tcp://localhost:26657", "broadcast-mode": "sync" }
  3. Git clone this repository into your desired location to get the client:

    $ git clone https://github.com/danburck/ethermint-simple-smart-contract $ cd ethermint-simple-smart-contract
  4. Configure the truffle-config in the project root to connect to your ethereum development client/node (EVM RPC HTTP server)

    networks: {    // Useful for testing. The `development` name is special - truffle uses it by default    // if it's defined here and no other network is specified at the command line.    // You should run a client (like ganache-cli, geth or parity) in a separate terminal    // tab if you use this network and you must also set the `host`, `port` and `network_id`    // options below to some value.    //    development: {    host: "127.0.0.1",     // Localhost (default: none)    port: 8545,            // Standard Ethereum port (default: none)    network_id: "*",       // Any network (default: none)  },

Usage

Define new smart ontracts at /contracts and tests at /tests. The project comes implemented with an ERC20 Token smart contract.

Deploy contracts

  1. Compile all contracts:

    $ truffle compile
  2. Deploy the contract to node network using:

    $ truffle migrate --network development

Run Tests

Truffle tests are based on Mocha and Chai. To compile and run the all unit tests, run:

$ truffle test --network development

Interact with the contract

Run the erc20.js script to deploy the ERC20 token smart contract and invoke balance queries and token transfers:

$ node scripts/erc20.js

Find a log of query results and transfer receipts, including information such as contract, address, gasUsed, totalSupply, balances and more.

Adding a new contracts

To add new contracts follow the following steps:

  # Add a new contract   $ touch contracts/MyContract.sol    # Write a new Contract    # Compile your contract.   $ truffle compile    # Create unit tests   $ touch test/my_contract.js    # Run tests    # Migrate your contract   $ truffle migrate    # Write a script to interact with your contract   $ touch scripts/my_contract.js

Observations

  • Node setup on macOS Catalina throws deprication errors errors at $ make install

  • Adding genesis account throws errors:

    Documentation could be more clear by removing the code:

    ethermintd add-genesis-account my_validator 10000000000aphoton --keyring-backend test

    and only including

    ethermintd add-genesis-account my_validator 1000000000stake,10000000000aphoton --keyring-backend=test

    Also it would be more clear to add the gentx command:

    ethermintd gentx my_validator 1000000stake --keyring-backend=test --chain-id=$CHAINID

    and movig the a hint to configure the node from the initialize section to run testnet

  • ethermintd tx bank send command should include fees:

    ethermintd tx bank send $MY_KEY $RECIPIENT 20000aphoton --chain-id=$CHAINID --keyring-backend=test --fees='1aphoton'
  • Connecting hardhat to the node throws an errors with the following hardhat.config:

    module.exports = {   networks: {     hardhat: {     },     development: {       url: "localhost:8545",       chainID: "ethermint_9000-1",     },   },   solidity: "0.8.4", };

    Running any command, e.g.

    npx hardhat accounts --network development

    throws the following error:

    An unexpected error occurred:  TypeError: Only HTTP(S) protocols are supported     at getNodeRequestOptions (/Users/danielburckhardt/code/hardhat-test/node_modules/node-fetch/lib/index.js:1309:9)     at /Users/danielburckhardt/code/hardhat-test/node_modules/node-fetch/lib/index.js:1410:19     at new Promise (<anonymous>)     at fetch (/Users/danielburckhardt/code/hardhat-test/node_modules/node-fetch/lib/index.js:1407:9)     at HttpProvider._fetchJsonRpcResponse (/Users/danielburckhardt/code/hardhat-test/node_modules/hardhat/src/internal/core/providers/http.ts:140:30)     at HttpProvider.request (/Users/danielburckhardt/code/hardhat-test/node_modules/hardhat/src/internal/core/providers/http.ts:55:29)     at GanacheGasMultiplierProvider._isGanache (/Users/danielburckhardt/code/hardhat-test/node_modules/hardhat/src/internal/core/providers/gas-providers.ts:302:30)     at GanacheGasMultiplierProvider.request (/Users/danielburckhardt/code/hardhat-test/node_modules/hardhat/src/internal/core/providers/gas-providers.ts:291:23)     at EthersProviderWrapper.send (/Users/danielburckhardt/code/hardhat-test/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)     at Object.getSigners (/Users/danielburckhardt/code/hardhat-test/node_modules/@nomiclabs/hardhat-ethers/src/internal/helpers.ts:23:20) 

ethermint简单智能合约

ethermint简单智能合约是使用ethermint部署简单智能合约的练习

它包括运行ethermint节点、部署本地ERC20令牌智能合约以及编写客户端程序来查询和传输部署的智能合约上的令牌余额

有关ethermint的更多信息,请参阅ethermint文档

  • 入门先决条件安装

先决条件

该项目的体系结构由客户端和ethermint节点组成。Ethermintd节点表示客户端可以与之交互的EVM区块链blockchain。客户机在区块链blockchain上部署/迁移合同,以使其可供Ethermint网络的用户使用。一旦合同部署到网络上,客户端就允许您与该合同进行交互

您可以使用诸如Truffle或Hardhat之类的框架1)定义智能合约,2)使用网络配置连接到节点网络,3)部署合约,4)运行测试,以及5)与部署合约交互。我考虑了以下实现选项:

  • Git将此存储库克隆到所需位置以获取客户端:$Git clonehttps://github.com/danburck/ethermint-simple-smart-contract $cd ethermint简单智能合约
  • 在项目根目录中配置块菌配置,以连接到以太坊eth开发客户端/节点(EVM RPCHTTP服务器)网络:{//对于测试非常有用。“development”名称是特殊的-默认情况下,truffle使用它//如果在这里定义了它,并且在命令行中没有指定其他网络。//如果使用此网络,则应在单独的终端//选项卡中运行客户端(如ganache cli、geth或parity),并且还必须将下面的“主机”、“端口”和“网络id”选项设置为某个值。//开发:{host:“127.0.0.1”,//本地主机(默认值:无)端口:8545,//标准以太坊eth端口(默认值:无)网络u id:“*”,//任何网络(默认值:无)},
  • 编译所有合同:$truffle Compile

安装

  • 使用:$truffle migrate–network development
  • 在macOS Catalina上的节点设置在$make install抛出去润滑错误添加genesis帐户抛出错误:通过删除代码:ethermintd add genesis account my_validator 1000000000 Aphoton–密钥环后端测试,仅包括ethermintd add genesis account my_validator 1000000000,1000000000aphoton–keyring backend=test另外,添加gentx命令会更清楚:ethermintd gentx my_validator 1000000000 stack–keyring backend=test–chain id=$chain id,并从initialize部分移动配置节点以运行testnet的提示bank send$MY_KEY$RECIPIENT 20000aphoton–chain id=$CHAINID–keyring backend=test–fees=’1aphoton’
  • 将hardhat连接到节点会引发以下hardhat.config错误:module.exports={networks:{hardhat:{},development:{url:“localhost:8545”,CHAINID:“ethermintu 9000-1”,},坚固性:“0.8.4”,};运行任何命令,例如,npx hardhat帐户–网络开发引发以下错误:发生意外错误:TypeError:GetNodeRequestStoptions(/Users/danielburckhardt/code/hardhat test/node_modules/node fetch/lib/index.js:1309:9)上只支持HTTP协议/Users/danielbuckhardt/code/hardhat test/node_modules/node fetch/lib/index.js:1410:19在新承诺中(&lt;匿名的在HttpProvider的fetch(/Users/danielbuckhardt/code/hardhat test/node_modules/node fetch/lib/index.js:1407:9)上获取(/Users/danielbuckhardt/code/hardhat test/node_modules/hardhat/src/internal/core/providers/http.ts:140:30)(/Users/danielbuckhardt/code/hardhat test/node_modules/hardhat/src/internal/core/providers/http.ts:55:29)在GanacheGasMultiplierProvider上。(isGanache(/Users/danielbuckhardt/code/hardhat test/node_modules/hardhat/src/internal/core/providers/gas.ts:302:30)在GanacheGanacheGasMultiplierProvider.request上)(/Users/danielburckhardt/code/hardhat test/node_modules/hardhat/src/internal/core/providers/gas providers.ts:291:23)在EthersProviderWrapper.send(/Users/danielburckhardt/code/hardhat test/node_modules/@nomiclabs/hardhat ethers/src/internal/ethers provider wrapper.ts:13:20)在Object.getSigners)(/Users/danielbuckhardt/code/hardhat test/node_modules/@nomiclabs/hardhat ethers/src/internal/helpers.ts:23:20)
  • JavaScript/TypeScript: web3.js
  • truffle 5.1.44

部署合约

  1. 安装npm包(例如solidity linter solhint):

    $ npm install 
  2. 按照Ethermint文档中的说明安装并启动本地Ethermintd节点。在启动节点之前,设置客户端配置以运行本地testnet:

    { "chain-id": "ethermint_9000-1", "keyring-backend": "test", "output": "text", "node": "tcp://localhost:26657", "broadcast-mode": "sync" }
  3. Git将此存储库克隆到所需位置以获取客户端:

    $ git clone https://github.com/danburck/ethermint-simple-smart-contract $ cd ethermint-simple-smart-contract
  4. 在项目根目录中配置块菌配置以连接到以太坊eth开发客户端/节点(EVM RPC HTTP服务器)

    networks: {    // Useful for testing. The `development` name is special - truffle uses it by default    // if it's defined here and no other network is specified at the command line.    // You should run a client (like ganache-cli, geth or parity) in a separate terminal    // tab if you use this network and you must also set the `host`, `port` and `network_id`    // options below to some value.    //    development: {    host: "127.0.0.1",     // Localhost (default: none)    port: 8545,            // Standard Ethereum port (default: none)    network_id: "*",       // Any network (default: none)  },

与合约互动

在/contracts和/tests定义新的智能合约和测试。该项目与ERC20代币智能合同一起实施

添加新合约ethermint简单智能合约入门先决条件安装使用情况部署合约运行测试与合约交互添加新合约观察
  • 入门先决条件安装
  • 安装
  • 使用情况部署合约运行测试与合同添加新合同
  • 部署合同
  • 运行测试

  • 与合同交互
  • 添加新合同
  • 观察
  • 块菌:使用块菌迁移部署合同——网络开发或使用ethers.js/web3.js部署合同并与合同交互
  • 安全帽:部署并与合同交互Geth:使用Geth控制台与部署的合同交互Node/Deno和npm/yarn安装npm软件包(例如solidity linter solhint):$npm安装
  • 按照Ethermint文档中的说明设置并启动本地Ethermint节点。在启动节点之前,将客户端配置设置为运行本地testnet:{“chain id”:“ethermint_9000-1”,“keyring backend”:“test”,“output”:“text”,“node”:tcp://localhost:26657″,“广播模式”:“sync”}
  • Git将此存储库克隆到所需位置以获取客户端:$Git clonehttps://github.com/danburck/ethermint-simple-smart-contract $cd ethermint简单智能合约
  • 在项目根目录中配置块菌配置,以连接到以太坊eth开发客户端/节点(EVM RPCHTTP服务器)网络:{//对于测试非常有用。“development”名称是特殊的-默认情况下,truffle使用它//如果在这里定义了它,并且在命令行中没有指定其他网络。//如果使用此网络,则应在单独的终端//选项卡中运行客户端(如ganache cli、geth或parity),并且还必须将下面的“主机”、“端口”和“网络id”选项设置为某个值。//开发:{host:“127.0.0.1”,//本地主机(默认值:无)端口:8545,//标准以太坊eth端口(默认值:无)网络u id:“*”,//任何网络(默认值:无)},
  • 编译所有合同:$truffle Compile
  • 使用:$truffle migrate–network development
  • 在macOS Catalina上的节点设置在$make install抛出去润滑错误添加genesis帐户抛出错误:通过删除代码:ethermintd add genesis account my_validator 1000000000 Aphoton–密钥环后端测试,仅包括ethermintd add genesis account my_validator 1000000000,1000000000aphoton–keyring backend=test另外,添加gentx命令会更清楚:ethermintd gentx my_validator 1000000000 stack–keyring backend=test–chain id=$chain id,并从initialize部分移动配置节点以运行testnet的提示bank send$MY_KEY$RECIPIENT 20000aphoton–chain id=$CHAINID–keyring backend=test–fees=’1aphoton’
  • 将hardhat连接到节点会引发以下hardhat.config错误:module.exports={networks:{hardhat:{},development:{url:“localhost:8545”,CHAINID:“ethermintu 9000-1”,},坚固性:“0.8.4”,};运行任何命令,例如,npx hardhat帐户–网络开发引发以下错误:发生意外错误:TypeError:GetNodeRequestStoptions(/Users/danielburckhardt/code/hardhat test/node_modules/node fetch/lib/index.js:1309:9)上只支持HTTP协议/Users/danielbuckhardt/code/hardhat test/node_modules/node fetch/lib/index.js:1410:19在新承诺中(&lt;匿名的在HttpProvider的fetch(/Users/danielbuckhardt/code/hardhat test/node_modules/node fetch/lib/index.js:1407:9)上获取(/Users/danielbuckhardt/code/hardhat test/node_modules/hardhat/src/internal/core/providers/http.ts:140:30)(/Users/danielbuckhardt/code/hardhat test/node_modules/hardhat/src/internal/core/providers/http.ts:55:29)在GanacheGasMultiplierProvider上。(isGanache(/Users/danielbuckhardt/code/hardhat test/node_modules/hardhat/src/internal/core/providers/gas.ts:302:30)在GanacheGanacheGasMultiplierProvider.request上)(/Users/danielburckhardt/code/hardhat test/node_modules/hardhat/src/internal/core/providers/gas providers.ts:291:23)在EthersProviderWrapper.send(/Users/danielburckhardt/code/hardhat test/node_modules/@nomiclabs/hardhat ethers/src/internal/ethers provider wrapper.ts:13:20)在Object.getSigners)(/Users/danielbuckhardt/code/hardhat test/node_modules/@nomiclabs/hardhat ethers/src/internal/helpers.ts:23:20)
    1. 编译所有合同:

      $ truffle compile
    2. 使用以下方法将合同部署到节点网络:

      $ truffle migrate --network development

    Run Tests

    块菌测试基于Mocha和Chai。要编译和运行所有单元测试,请运行:

    $ truffle test --network development

    Interact with the contract

    运行erc20.js脚本以部署erc20令牌智能合约并调用余额查询和令牌传输:

    $ node scripts/erc20.js

    查找查询结果和传输收据的日志,包括合约、地址、已用气体、totalSupply、余额等信息

    Adding a new contracts

    要添加新合同,请遵循以下步骤:

      # Add a new contract   $ touch contracts/MyContract.sol    # Write a new Contract    # Compile your contract.   $ truffle compile    # Create unit tests   $ touch test/my_contract.js    # Run tests    # Migrate your contract   $ truffle migrate    # Write a script to interact with your contract   $ touch scripts/my_contract.js

    Observations

    • macOS Catalina上的节点设置会在$make install抛出去润滑错误

    • Adding genesis account throws errors:

      添加genesis帐户会抛出错误:

      ethermintd add-genesis-account my_validator 10000000000aphoton --keyring-backend test

      通过删除代码,文档可能会更清晰:

      ethermintd add-genesis-account my_validator 1000000000stake,10000000000aphoton --keyring-backend=test

      ,并且只包括

      ethermintd gentx my_validator 1000000stake --keyring-backend=test --chain-id=$CHAINID

      and movig the a hint to configure the node from the initialize section to run testnet

    • ,添加gentx也会更清晰命令:

      ethermintd tx bank send $MY_KEY $RECIPIENT 20000aphoton --chain-id=$CHAINID --keyring-backend=test --fees='1aphoton'
    • 并从初始化部分移动配置节点的提示以运行testnet

      module.exports = {   networks: {     hardhat: {     },     development: {       url: "localhost:8545",       chainID: "ethermint_9000-1",     },   },   solidity: "0.8.4", };

      ethermintd tx bank send命令应包括费用:

      npx hardhat accounts --network development

      将hardhat连接到节点会引发以下hardhat.config错误:

      An unexpected error occurred:  TypeError: Only HTTP(S) protocols are supported     at getNodeRequestOptions (/Users/danielburckhardt/code/hardhat-test/node_modules/node-fetch/lib/index.js:1309:9)     at /Users/danielburckhardt/code/hardhat-test/node_modules/node-fetch/lib/index.js:1410:19     at new Promise (<anonymous>)     at fetch (/Users/danielburckhardt/code/hardhat-test/node_modules/node-fetch/lib/index.js:1407:9)     at HttpProvider._fetchJsonRpcResponse (/Users/danielburckhardt/code/hardhat-test/node_modules/hardhat/src/internal/core/providers/http.ts:140:30)     at HttpProvider.request (/Users/danielburckhardt/code/hardhat-test/node_modules/hardhat/src/internal/core/providers/http.ts:55:29)     at GanacheGasMultiplierProvider._isGanache (/Users/danielburckhardt/code/hardhat-test/node_modules/hardhat/src/internal/core/providers/gas-providers.ts:302:30)     at GanacheGasMultiplierProvider.request (/Users/danielburckhardt/code/hardhat-test/node_modules/hardhat/src/internal/core/providers/gas-providers.ts:291:23)     at EthersProviderWrapper.send (/Users/danielburckhardt/code/hardhat-test/node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)     at Object.getSigners (/Users/danielburckhardt/code/hardhat-test/node_modules/@nomiclabs/hardhat-ethers/src/internal/helpers.ts:23:20) 

    部分转自网络,侵权联系删除区块链源码网

    www.interchains.cc

    https://www.interchains.cc/24163.html

    区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 ! QQ3039046426
    区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » 基于区块链的毕业设计ethermint-simple-smart-contract – ethermint简单智能合约

    提供最优质的资源集合

    立即查看 了解详情