程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Solidity 智能合约迁移错误的 Truffle 和 Ganache 教程大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Solidity 智能合约迁移错误的 Truffle 和 Ganache 教程?

开发过程中遇到Solidity 智能合约迁移错误的 Truffle 和 Ganache 教程的问题如何解决?下面主要结合日常开发的经验,给出你关于Solidity 智能合约迁移错误的 Truffle 和 Ganache 教程的解决方法建议,希望对你解决Solidity 智能合约迁移错误的 Truffle 和 Ganache 教程有所启发或帮助;

按照“以太坊开发演练(第 2 部分:Truffle、Ganache、Geth 和 Mist)”的教程,我大致初始化了 truffle 文件夹,复制到 Wrestling.sol 上,运行 compile truffle,但是,在运行 @H_983_3@migrate 后,我没有看到任何关于从 ganache 部署合同的消息。

每一步似乎都已正确完成:

松露使用

nicholas@mordor:~/truffle$ ll
@R_791_10586@l 8
drwxrwxr-x  2 nicholas nicholas 4096 Apr 15 15:24 ./
drwxr-xr-x 71 nicholas nicholas 4096 Apr 15 15:18 ../
nicholas@mordor:~/truffle$ 
nicholas@mordor:~/truffle$ truffle init

StarTing init...
================

> copying project files to /home/nicholas/truffle

Init successful,sweet!

nicholas@mordor:~/truffle$ 
nicholas@mordor:~/truffle$ cp /home/nicholas/git/ethereum-walkthrough-1/Wrestling.sol . -vi
'/home/nicholas/git/ethereum-walkthrough-1/Wrestling.sol' -> './Wrestling.sol'
nicholas@mordor:~/truffle$ 
nicholas@mordor:~/truffle$ ll
@R_791_10586@l 32
drwxrwxr-x  5 nicholas nicholas 4096 Apr 15 15:24 ./
drwxr-xr-x 71 nicholas nicholas 4096 Apr 15 15:18 ../
drwxr-xr-x  2 nicholas nicholas 4096 Apr 15 15:24 contracts/
drwxr-xr-x  2 nicholas nicholas 4096 Apr 15 15:24 migrations/
drwxr-xr-x  2 nicholas nicholas 4096 Apr 15 15:24 test/
-rw-r--r--  1 nicholas nicholas 4598 Apr 15 15:24 truffle-config.Js
-rw-rw-r--  1 nicholas nicholas 2708 Apr 15 15:24 Wrestling.sol
nicholas@mordor:~/truffle$ 
nicholas@mordor:~/truffle$ mv truffle-config.Js truffle-config.Js.bkup
nicholas@mordor:~/truffle$ 
nicholas@mordor:~/truffle$ nano truffle-config.Js 
nicholas@mordor:~/truffle$ 
nicholas@mordor:~/truffle$ cat truffle-config.Js
module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // for more about customizing your Truffle configuration!
  networks: {
    development: {
      host: "127.0.0.1",port: 7545,network_ID: "*" // Match any network ID
    }
  }
};

nicholas@mordor:~/truffle$ 
nicholas@mordor:~/truffle$ truffle compile

Compiling your contracts...
===========================
✔ Fetching solc version List from solc-bin. Attempt #1
✔ Downloading compiler. Attempt #1.
> Compiling ./contracts/Migrations.sol
> Artifacts written to /home/nicholas/truffle/build/contracts
> Compiled successfully using:
   - solc: 0.5.16+commit.9c3226ce.Emscripten.clang

nicholas@mordor:~/truffle$ 
nicholas@mordor:~/truffle$ truffle migrate --network development

Compiling your contracts...
===========================
> Everything is up to date,there is nothing to compile.



StarTing migrations...
======================
> Network name:    'development'
> Network ID:      1618525649277
> Block gas limit: 6721975 (0x6691b7)


1_initial_migration.Js
======================

   deploying 'Migrations'
   ----------------------
   > transaction hash:    0xb6045e7573e3834c4c79eb935e83500974d499f9d32dd7933b3dfa1631bb681d
   > Blocks: 0            Seconds: 0
   > contract address:    0xebCf528c359E57f5300bD0fb1Ae2911CD7581132
   > block number:        1
   > block timestamp:     1618525749
   > account:             0xAF400c33455309896aD4A3ceF3e9b801f4b84601
   > balance:             99.99616114
   > gas used:            191943 (0x2edc7)
   > gas price:           20 gwei
   > value sent:          0 ETH
   > @R_791_10586@l cost:          0.00383886 ETH


   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > @R_791_10586@l cost:          0.00383886 ETH


SumMary
=======
> @R_791_10586@l deployments:   1
> Final cost:          0.00383886 ETH


nicholas@mordor:~/truffle$ 
nicholas@mordor:~/truffle$ pwd
/home/nicholas/truffle
nicholas@mordor:~/truffle$

甘纳许控制台

nicholas@mordor:~/truffle$ ganache-cli -p 7545
Ganache Cli v6.12.2 (ganache-core: 2.13.2)

Available Accounts
==================
(0) 0xAF400c33455309896aD4A3ceF3e9b801f4b84601 (100 ETH)
(1) 0xCCCfA7723c87e987d05FfF47Cff11387519e8977 (100 ETH)
(2) 0xe05d12C9369F0D38a9bf3E710fceF7a480808114 (100 ETH)
(3) 0xd1988F3E8f53F096024EE240c1E0a411dfcfe6aE (100 ETH)
(4) 0x234b8f036e925A15D2B2760903d8F364f41fA064 (100 ETH)
(5) 0x27B5466FF034F1904568de1500Daf0f0A70d5393 (100 ETH)
(6) 0xd969E5d5E14c85329e9369e61Ac36301BE0E4287 (100 ETH)
(7) 0xC13e11eEA25ED477cEF68b512c0Fcd6113996369 (100 ETH)
(8) 0xB2d8e219eBFE5Ee3B0E4acE09DD30bfD5881FBa5 (100 ETH)
(9) 0xC1983b4ABfC233de38E00fD3727e0461f86535ee (100 ETH)

Private Keys
==================
(0) 0xca62f6371c91ee3843fbe4764c02612b05f388394510cc4000467a719499685f
(1) 0x6016ebd988cea6f78aa232f6aab40cada947ada74f928d87de86db825b7b11e5
(2) 0x6d1cFeed4f1748cb8a685c449960023cfae4fa5a7eba0087cb24c558594d2054
(3) 0x5d99edc99844c968b380088f1856995952307b91f533198ced4a706bbada9b62
(4) 0x0c7798bd411444673a3640311dd742b7daf944a93d936047b420e50d70a9ca90
(5) 0xf25d7a8f89aa63a7fef85192d7f9108494cf855c269d941378d9d7ffbd8c161c
(6) 0x7317293b8cd55dcce8a7729bfeaACB0265522348ecfdd992e353fc4d33e5ec99
(7) 0x5d257a1fb44624c4de13fea1d75cb708b8922936565cb3fa0dabb2e218e2c6a5
(8) 0x9e758500b8cd79757bb4eb307e3c1005d66984ec38ab47de219d81d803fd994c
(9) 0xe26b033f6e307cb3fc0784fe982fc00681c37389aee79dad69b33db4d4ef050d

HD Wallet
==================
Mnemonic:      person Dice develop erupt pilot purpose cool bomb inherit cloth Metal canal
Base HD Path:  m/44'/60'/0'/0/{account_index}

Gas Price
==================
20000000000

Gas limit
==================
6721975

Call Gas limit
==================
9007199254740991

Listening on 127.0.0.1:7545
eth_blocknumber
net_version
eth_accounts
eth_getBlockBynumber
eth_accounts
net_version
eth_getBlockBynumber
eth_getBlockBynumber
net_version
eth_getBlockBynumber
eth_estimateGas
net_version
eth_blocknumber
eth_getBlockBynumber
net_version
eth_sendtransaction

  transaction: 0xb6045e7573e3834c4c79eb935e83500974d499f9d32dd7933b3dfa1631bb681d
  Contract created: 0xebcf528c359e57f5300bd0fb1ae2911cd7581132
  Gas usage: 191943
  Block number: 1
  Block Time: Thu Apr 15 2021 15:29:09 GMT-0700 (Pacific Daylight TimE)

eth_gettransactionReceipt
eth_getCode
eth_gettransactionByHash
eth_getBlockBynumber
eth_getBalance
eth_getBlockBynumber
eth_getBlockBynumber
eth_sendtransaction

  transaction: 0xaefa402a80b986a218cecc26b215d3c06ccc557030bbe4bd1371978404164a64
  Gas usage: 42338
  Block number: 2
  Block Time: Thu Apr 15 2021 15:29:09 GMT-0700 (Pacific Daylight TimE)

eth_gettransactionReceipt

但也许是跳过了某个步骤或做错了?

解决方法

您需要将 Wrestling.sol 移动到 contracts 文件夹。并创建部署 JS 代码。


正如 tutorial 所说:

然后将上一教程中的 Wrestling.sol 文件复制到“contracts”文件夹中。

接下来,打开文件夹“MIgrations”并创建一个名为“2_deploy_contracts.js”的新文件。迁移只是帮助我们将合约部署到区块链的脚本。

将以下代码粘贴进去,然后保存。

const Wrestling = artifacts.require("./Wrestling.sol")

module.exports = function(deployer) {
  deployer.deploy(Wrestling);
};

大佬总结

以上是大佬教程为你收集整理的Solidity 智能合约迁移错误的 Truffle 和 Ganache 教程全部内容,希望文章能够帮你解决Solidity 智能合约迁移错误的 Truffle 和 Ganache 教程所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:教程