使用Truffle 在Moonbeam上部署合约

报错:Error: Expected parameter 'from' not passed to function.

EVM/moonbeam_doc/Using with Truffle/TruffleTest/MetaCoin$ truffle migrate

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

Error: Expected parameter 'from' not passed to function.
    at has (/usr/local/lib/node_modules/truffle/build/webpack:/packages/expect/dist/src/index.js:10:1)
    at Object.options (/usr/local/lib/node_modules/truffle/build/webpack:/packages/expect/dist/src/index.js:19:1)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:65:1)
    at runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:258:1)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:223:1)
    at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:172:1)
Truffle v5.4.3 (core: 5.4.3)
Node v14.15.5

解决:
在trufle-config.js中添加:from参数,表示哪个账户在部署合约
添加前:

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 9933,
      network_id: "*",     

    }
  }        

};

添加后:

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 9933,
      network_id: "*",
      from: "0x6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b",

    }
  }        

};

0x6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b 是节点内置的以太坊账户。

再次部署:truffle migrate,报错:no signer available.

EVM/moonbeam_doc/Using with Truffle/TruffleTest/MetaCoin$ truffle migrate

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



Starting migrations...
======================
> Network name:    'development'
> Network id:      1281
> Block gas limit: 15000000 (0xe4e1c0)


1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------

Error:  *** Deployment Failed ***

"Migrations" -- Returned error: no signer available.

    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:365:1
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at Migration._deploy (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:70:1)
    at Migration._load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:56:1)
    at Migration.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:217:1)
    at Object.runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:150:1)
    at Object.runFrom (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:110:1)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:87:1)
    at runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:258:1)
    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:223:1)
    at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:172:1)
Truffle v5.4.3 (core: 5.4.3)
Node v14.15.5

查看账户
先进入truffle控制台:

truffle console

默认账户:

truffle migrate命令运行迁移脚本来部署合约。

执行truffle migrate时使用的账户是哪个?
web3.eth.defaultAccount – 默认账户

web3.eth.defaultAccount属性记录了默认地址,在以下方法中如果没有指定from属性,将使用web3.eth.defaultAccount属性的值作为默认的from属性值。

  • web3.eth.sendTransaction()
  • web3.eth.call()
  • new web3.eth.Contract() -> myContract.methods.myMethod().call()
  • new web3.eth.Contract() -> myContract.methods.myMethod().send()

调用:

web3.eth.defaultAccount

属性:
String – 20 Bytes: 以太坊地址,你应当在节点或keystore中存有该地址的私钥。默认值为undefined

示例代码:

web3.eth.defaultAccount;
> undefined

// set the default account
web3.eth.defaultAccount = '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe';

ganache-cli预置了10个账户,truffle migrate默认使用预置第一个的账户进行部署合约。

相关内容:
https://www.trufflesuite.com/docs/truffle/getting-started/interacting-with-your-contracts

Truffle/npm error “Expected parameter ‘from’ not passed to function”
Truffle实践
Default Truffle project gives ‘Expected parameter ‘from’ not passed to function.’ error after ‘truffle migrate’ command #548

快速入门 Truffle

详解 Truffle Migrations(迁移)- 合约部署不再困惑
以太坊开发学习笔记 - truffle migrate

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值