solidity - 它如何管理私钥松露?
问题描述
我正在尝试在部署在 ropsten 中的 mi 自定义合同中发送令牌。另外,我正在使用 truffle 和 truffle-contract 1.1.11 库。我的疑问是,我应该如何在松露环境中签署交易?
另一方面,如果可能的话,我想知道 truffle 是如何管理私钥的,因为当我在本地 ganache 区块链上设置项目时,我所有的东西都可以工作。当我尝试从与合约部署地址不同的另一个地址签署交易时,它只是神奇的访客私钥。这当然是在 ganache 中,但问题在于 ropsten。
pragma solidity ^0.5.0;
import "@openzeppelin/contracts/token/ERC20/ERC20Detailed.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Mintable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Burnable.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20Pausable.sol";
contract CustomToken is ERC20Pausable, ERC20Burnable, ERC20Mintable, ERC20Detailed {
constructor () public ERC20Detailed("CustomToken", "CT", 2) { }
// some functions who call super.function(), this reproduces default behavior of a base ERC20 token
}
const contract = require('truffle-contract');
const customtoken_artifact = require('../build/contracts/CustomToken.json');
let CustomToken = contract(customtoken_artifact);
module.exports = {
sendCoin: function(amount, sender, receiver, callback) {
let self = this;
CustomToken.setProvider(self.web3.currentProvider);
let custom;
CustomToken.deployed().then(function(instance) {
custom = instance;
return custom.transfer(receiver, amount, {from: sender});
}).then(() => callback("202"))
.catch(function(e) {
console.log(e);
callback("400 " + e);
});
},
};
最后,我希望知道 truffle 如何管理私钥或何时签署交易。
解决方案
要在 Truffle 中签署交易,您可以使用HDWalletProvider
:
https://www.npmjs.com/package/@truffle/hdwallet-provider
你可以在你的truffle-config.js
推荐阅读
- javascript - Zapier 自定义响应对象
- express - 无法使用 passport-jwt 访问受保护的路线
- tensorflow - 如何在 TensorFlow 中计算次梯度?
- scala - 为什么 Scala 强制使用 Await 而不是 Awaitable?
- mysql - 使用带有 Helm 安装的 Kafka/Confluent 的连接器
- knex.js - 使用 Knex 发布迁移代码段
- html - 有什么意义 tag?
- c - 为什么 _mm_permute_ps 的最后一个参数是 int?
- angular - 角度路由器 - 重定向时的错误网址
- java - 如何将元素添加到 JList 中?库存产品计划