2

I am having trouble deploying my smart contract to the ropsten network using infura and truffle am getting error that says

"var sig = secp256k1.sign(msgHash, privateKey);
                      ^
TypeError: private key should be a Buffer"
  • 3
    can you share some code / link of a tutorial you used ? – Nikita Fuchs Jun 27 '18 at 9:24
  • It appears you are passing an incorrect format for privateKey. If you have the hexadecimal private key you should pass as raw bytes instead const privateKey = Buffer.from("ab1a..", "hex"); – Ismael Jun 30 '18 at 20:02
0

You can find how to deploy a contract using truffle and infura as it is explained truffle documentation

I copied the deployment code that I already owned below,

// Allows us to use ES6 in our migrations and tests.
require('babel-register')

const HDWalletProvider = require("truffle-hdwallet-provider-privkey");

const privateKey = "PRIVATEKEYADDRESS"; // private keys

module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // for more about customizing your Truffle configuration!
  networks: {
    development: {
      host: "127.0.0.1",
      port: 8545,
      network_id: "*" // Match any network id
    },
    rinkeby: {
      provider: () => {
        return new HDWalletProvider(privateKey, "https://rinkeby.infura.io/INFURAAPIKEY")
      },
      network_id: 4
    }
  }
};

Hope it works for you as well

  • Mehmet Dogan Thanks for the help but am still getting another error it outputs Error encountered, bailing. Network state unknown. Review successful transactions manually. insufficient funds for gas * price + value – daniel Jun 28 '18 at 8:03
  • You share little with us and want to get full answer. But as far I know, this error is encountered when you try to deploy an Interface which includes unimplemented functions like ERC20Interface. Assuming that you try to deploy a contract named myContract contract myContract is ERC20Interface { .. } Then you just need to include myContract in your 2_deploy_contracts.js file – Mehmet Doğan Jun 28 '18 at 17:58
0

You have to use 'from' address in lower case while deploying the contract to test network inorder to avoid this error.

  • Your answer is unrelated to the question asked. – Ismael Dec 6 '18 at 21:16
  • Give a try. Actually, it worked for me and hence I responded!! – Gayathri Suresh Dec 7 '18 at 15:45
  • The function used secp256k1.sign doesn't accept a from parameter. – Ismael Dec 7 '18 at 19:45
  • If you are deploying your contract like this for example: SampleContract.new(abcd, {from: '0xAD123EFG456...'}).then(function(){}); then the from address should be in small letters like SampleContract.new(abcd, {from: '0xad123efg456...'}).then(function(){}); – Gayathri Suresh Dec 8 '18 at 12:28
0

Agree with Ismael saying the function sepc256k1.sign won't need from parameter. worked for me without private keys declaration and from parameter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.