注意:由于besu不支持私钥管理,所以使用truffle时需要配置一个钱包。
安装钱包
npm install --save @truffle/hdwallet-provider
更新配置文件
在工程目录文件truffle-config.js
中添加wallet provider,示例如下:
const PrivateKeyProvider = require("@truffle/hdwallet-provider");
const privateKey = "<account-private-key>";
const privateKeyProvider = new PrivateKeyProvider(privateKey, "<JSON-RPC-http-endpoint>");
module.exports = {
// See <http://truffleframework.com/docs/advanced/configuration>
// for more about customizing your Truffle configuration!
networks: {
besuWallet: {
provider: privateKeyProvider,
network_id: "*"
},
}
};
部署合约
truffle migrate --network besuWallet
输出示例:
D:\mygithub\tasks\truffle\MetaCoin>truffle migrate --network besuWallet
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
Starting migrations...
======================
> Network name: 'besuWallet'
> Network id: 1337
> Block gas limit: 16234336 (0xf7b760)
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
> transaction hash: 0x465cfe361299d954aa74bebe2d4bcb98bad6a89b443b6ee6973e429e604842c5
> Blocks: 0 Seconds: 4
> contract address: 0x9ab7CA8a88F8e351f9b0eEEA5777929210199295
> block number: 91004
> block timestamp: 1623920385
> account: 0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73
> balance: 200
> gas used: 188483 (0x2e043)
> gas price: 0 gwei
> value sent: 0 ETH
> total cost: 0 ETH
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0 ETH
2_deploy_contracts.js
=====================
Deploying 'ConvertLib'
----------------------
> transaction hash: 0x521b97e3e9d76675c63ec8ab1b8fabeb792642e16257e25ae035430f6d13eb99
> Blocks: 0 Seconds: 4
> contract address: 0x4245CF4518CB2C280f5e9c6a03c90C147F80B4d9
> block number: 91008
> block timestamp: 1623920400
> account: 0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73
> balance: 200
> gas used: 105974 (0x19df6)
> gas price: 0 gwei
> value sent: 0 ETH
> total cost: 0 ETH
Linking
-------
* Contract: MetaCoin <--> Library: ConvertLib (at address: 0x4245CF4518CB2C280f5e9c6a03c90C147F80B4d9)
Deploying 'MetaCoin'
--------------------
> transaction hash: 0x82b950747716c117861270beee891b053c1168fe6a11cd2eb4cc408b1ad3b596
> Blocks: 2 Seconds: 4
> contract address: 0x5EB5888938e3fE7b334b1838B19C1e828c5148aA
> block number: 91012
> block timestamp: 1623920408
> account: 0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73
> balance: 200
> gas used: 340697 (0x532d9)
> gas price: 0 gwei
> value sent: 0 ETH
> total cost: 0 ETH
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0 ETH
Summary
=======
> Total deployments: 3
> Final cost: 0 ETH
网友评论