報錯: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 Migrations(遷移)- 合約部署不再困惑
以太坊開發學習筆記 - truffle migrate
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/292413.html
標籤:區塊鏈
上一篇:JAVA代碼實作區塊鏈模型
