How it manage private keys truffle?

by Agus Velez   Last Updated September 10, 2019 23:28 PM - source

I'm trying send tokens in mi custom contract which is deployed in ropsten. Also, I'm working with truffle and truffle-contract 1.1.11 library. My doubt is, how should I sign transactions inside the environment of truffle?

On other hand, if it possible, I would like know how is truffle managing the private keys, because when I set up the project on local ganache blockchain all my stuff works. When I try to sign a transaction from another address different from the contract deploy address, it just magically guest private keys. This of course is in ganache but the problem is in 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;


        let custom;

        CustomToken.deployed().then(function(instance) {

            custom = instance;

            return custom.transfer(receiver, amount, {from: sender});

        }).then(() => callback("202"))
            .catch(function(e) {
                callback("400 " + e);

Finally, I expect know how is truffle managing the private keys or when I should sign the transaction.

Related Questions

Truffle invalid address

Updated July 31, 2017 09:28 AM

Listen to emitted event from front-end

Updated April 02, 2018 23:28 PM