Can't deploy Dapp to rinkeby - ethereum

The problem
When I try to deploy to rinkeby using the command
truffle migrate --reset --network rinkeby
I get the following result after I run the above command. The actual error is further down. Please any pointers to what I can do to fix this is very welcome.
Starting migrations...
======================
> Network name: 'rinkeby'
> Network id: 4
> Block gas limit: 0x98705c
1_initial_migration.js
======================
Replacing 'Migrations'
----------------------
> transaction hash: 0x14bdcbb929d5c81530f4af1468ab3e84bdfb72a2369fdbff5c9645c06735aa9d
> Blocks: 1 Seconds: 17
> contract address: 0x88401B02262B3d4C3A3B1BfCeDf00e0531fa0d38
> block number: 5642911
> block timestamp: 1576782953
> account: 0x6b4119610F218E058C332c59Ed6b26DA8c045a87
> balance: 18.64313901
> gas used: 225237
> gas price: 10 gwei
> value sent: 0 ETH
> total cost: 0.00225237 ETH
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0.00225237 ETH
2_deploy_contracts.js
=====================
Replacing 'StarNotary'
----------------------
> transaction hash: 0xa4cda00d28cdc34ddb462b8c779c88378003bccfa50c5956cbd3bc587a2f9ffc
> Blocks: 0 Seconds: 9
> contract address: 0xC35D4d083E9F16B8253Ec26c9a64afB0af22c3c3
> block number: 5642913
> block timestamp: 1576782983
> account: 0x6b4119610F218E058C332c59Ed6b26DA8c045a87
> balance: 18.61937604
> gas used: 2333934
> gas price: 10 gwei
> value sent: 0 ETH
> total cost: 0.02333934 ETH
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0.02333934 ETH
Summary
=======
> Total deployments: 2
> Final cost: 0.02559171 ETH
truffle(develop)> Error: Invalid JSON RPC response: ""
at Object.InvalidResponse (C:\Workspace\BlockChainProjects\StarNotaryv2\node_modules\web3-core-helpers\src\errors.js:42:16)
at XMLHttpRequest.request.onreadystatechange (C:\Workspace\BlockChainProjects\StarNotaryv2\node_modules\web3-providers-http\src\index.js:92:32)
at XMLHttpRequestEventTarget.dispatchEvent (C:\Workspace\BlockChainProjects\StarNotaryv2\node_modules\xhr2-cookies\xml-http-request-event-target.ts:44:13)
at XMLHttpRequest._setReadyState (C:\Workspace\BlockChainProjects\StarNotaryv2\node_modules\xhr2-cookies\xml-http-request.ts:219:8)
at XMLHttpRequest._onHttpRequestError (C:\Workspace\BlockChainProjects\StarNotaryv2\node_modules\xhr2-cookies\xml-http-request.ts:379:8)
at ClientRequest.<anonymous> (C:\Workspace\BlockChainProjects\StarNotaryv2\node_modules\xhr2-cookies\xml-http-request.ts:266:37)
at ClientRequest.emit (events.js:198:13)
at ClientRequest.EventEmitter.emit (domain.js:448:20)
at TLSSocket.socketErrorListener (_http_client.js:392:9)
at TLSSocket.emit (events.js:198:13)
at TLSSocket.EventEmitter.emit (domain.js:448:20)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at process._tickCallback (internal/process/next_tick.js:63:19)
Here is my truffle.js config, please I'm new to DApp development on the etherum blockchain.
const HDWalletProvider = require("#truffle/hdwallet-provider");
const infuraKey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
const fs = require('fs');
const mnemonic = fs.readFileSync(".secret").toString().trim();
module.exports = {
networks: {
development: {
host: "127.0.0.1", // Localhost (default: none)
port: 9545, // Standard Ethereum port (default: none)
network_id: "*", // Any network (default: none)
},
rinkeby: {
provider: () => new HDWalletProvider(mnemonic, `https://rinkeby.infura.io/v3/${infuraKey}`),
network_id: 4, // rinkeby's id
gas: 4500000, // rinkeby has a lower block limit than mainnet
gasPrice: 10000000000
},
}
}
Please how do I fix this issue.
Thanks

truffle-hdwallet-provider is deprecated. It has been moved under the monorepo at trufflesuit/truffle. You should use that version. You can install it via
$ npm install #truffle/hdwallet-provider
In truffle-config.js
const HDWalletProvider = require("#truffle/hdwallet-provider");

Related

Unable to deploy an ERC 720 token in Mumbai Test says insufficient funds

I was trying to deploy an ERC 721 token using truffle in Polygon's mumbai testnet.
And i have 2.8296 Matic in my metasmask wallet which i got from their faucet. But when i try to run
truffle migrate --network matic
it says
Error: *** Deployment Failed ***
"Migrations" could not deploy due to insufficient funds
* Account: 0x12aADAdd301d22c941DACF2cfa7A9e2019972F61
* Balance: 0 wei
* Message: insufficient funds for gas * price + value
* Try:
+ Using an adequately funded account
+ If you are using a local Geth node, verify that your node is synced.
Am i doing something wrong? What sould be the gas and gas price i should mention in truffle config file.
Here is my truffle-config file
module.exports = {
networks: {
development: {
host: "127.0.0.1", // Localhost (default: none)
port: 8545, // Standard Ethereum port (default: none)
network_id: "*", // Any network (default: none)
},
matic: {
provider: () => new HDWalletProvider(process.env.MNEMONIC, `https://rpc-mumbai.maticvigil.com/v1/91fdbb5c2f37c699621ss7d2b8b127fc1a123060
`),
network_id: 80001,
confirmations: 2,
timeoutBlocks: 200,
skipDryRun: true
},
},
// Set default mocha options here, use special reporters etc.
mocha: {
// timeout: 100000
},
enter image description here
I am pretty sure there is no balance of this account 0x12aADAdd301d22c941DACF2cfa7A9e2019972F61 in Mumbai-Testnet

Truffle: Sender doesn't have enough funds to send tx

I'm trying to migrate/test my smart contract on ropsten network using this config:
networks: {
ropsten: {
provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/${infuraKey}`),
network_id: 3, // Ropsten's id
gas: 3000000,
}
},
running truffle migrate --network ropsten
but I keep getting this error:
Error: *** Deployment Failed ***
"Migrations" could not deploy due to insufficient funds
* Account: **address**
* Balance: 0 wei
* Message: sender doesn't have enough funds to send tx. The upfront cost is: 6000000000000000 and the sender's account only has: 0
How do I show truffle I have sufficient funds?
Your Ropsten account needs to have ETH in order to interact with the network.

How to fix 'Truffle Migrate' bytecode undefined error

Spent a few hours trying to figure this out - hoping someone has encountered this. (in testing) All the testing files run.
When running truffle migrate --reset it logs the below.
Versions that may be useful are Truffle v5.1.58 (core: 5.1.58), Node v12.13.0 and also using pragma solidity >=0.6.0 for all smart contracts contracts.
EDIT:
Have tried all sorts at this point. Different coompilers, using solcjs and just solc - no dice.
Compiling your contracts...
===========================
✔ Fetching solc version list from solc-bin. Attempt #1
> Compiling ./src/contracts/Exchange.sol
> Compiling ./src/contracts/Migrations.sol
> Compiling ./src/contracts/Token.sol
> Compiling openzeppelin-solidity/contracts/math/SafeMath.sol
✔ Fetching solc version list from solc-bin. Attempt #1
> Artifacts written to /Users/tony/Desktop/blockchain/el-capitan-exchange/src/abis
> Compiled successfully using:
- solc: 0.6.12+commit.27d51765.Emscripten.clang
Starting migrations...
======================
> Network name: 'development'
> Network id: 5777
> Block gas limit: 6721975 (0x6691b7)
1_initial_migration.js
======================
Replacing 'Migrations'
----------------------
> transaction hash: 0x1ce9b2b65807be1e20fcabd9e2c232ea01b64ce60f256e68749ed40a61db4392
> Blocks: 0 Seconds: 0
> contract address: 0x54A13cb54bD547f749a32959118cDb3E7c2b0Ee9
> block number: 31
> block timestamp: 1610569925
> account: 0x4f41f50211b97527a625BbE86D9Bed6AEBD85321
> balance: 99.77302744
> gas used: 186951 (0x2da47)
> gas price: 20 gwei
> value sent: 0 ETH
> total cost: 0.00373902 ETH
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0.00373902 ETH
2_deploy_contracts.js
=====================
Replacing 'Token'
-----------------
> transaction hash: 0xa7104779b88389cc116e9c9492ee26b5a6824dda7505ebb3a4860476d374cfa6
> Blocks: 0 Seconds: 0
> contract address: 0xC30B06Df705b2B86ebF46E61F799Ee5B0d476229
> block number: 33
> block timestamp: 1610569926
> account: 0x4f41f50211b97527a625BbE86D9Bed6AEBD85321
> balance: 99.75454758
> gas used: 881658 (0xd73fa)
> gas price: 20 gwei
> value sent: 0 ETH
> total cost: 0.01763316 ETH
TypeError: Cannot read property 'bytecode' of undefined
at Deployer._preFlightCheck (/Users/tony/.nvm/versions/node/v12.13.0/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:173:1)
at /Users/tony/.nvm/versions/node/v12.13.0/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:282:1
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Truffle v5.1.58 (core: 5.1.58)
Node v12.13.0
I just got a similar error because I had
await deployer.deploy();
in my migration file. You must enter the contract argument
await deployer.deploy(MyToken);

Truffle Smart Contract Error: Invalid number of parameter

I followed the tutorial of quorum with truffle: https://truffleframework.com/tutorials/building-dapps-for-quorum-private-enterprise-blockchains
Now I want to migrate the SimpleStorage.sol Smart Contract to the blockchain, but I want to make it to add the "PrivateFor" parameter.
This is my Smart Contract:
pragma solidity ^0.4.17;
contract SimpleStorage {
uint public storedData;
constructor(uint initVal) public {
storedData = initVal;
}
function set(uint x) public {
storedData = x;
}
function get() view public returns (uint retVal) {
return storedData;
}
}
This is my: 2_deploy_simplestorage.js
var SimpleStorage = artifacts.require("SimpleStorage");
module.exports = function(deployer) {
deployer.deploy(SimpleStorage, 42, {privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]})
};
But when I do truffle migrate, I get this error:
$ truffle migrate
⚠️ Important ⚠️
If you're using an HDWalletProvider, it must be Web3 1.0 enabled or your migration will hang.
Starting migrations...
======================
> Network name: 'development'
> Network id: 10
> Block gas limit: 3758096384
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
> transaction hash: 0x0a55cd010bb30247c3ae303e54be8dd13177b520af5967728cf77e07ca9efe76
- Blocks: 0 Seconds: 0
> Blocks: 0 Seconds: 0
> contract address: 0x1932c48b2bF8102Ba33B4A6B545C32236e342f34
> account: 0xed9d02e382b34818e88B88a309c7fe71E65f419d
> balance: 1000000000
> gas used: 245462
> gas price: 0 gwei
> value sent: 0 ETH
> total cost: 0 ETH
- Saving migration to chain.
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0 ETH
2_deploy_simplestorage.js
=========================
Deploying 'SimpleStorage'
-------------------------
Error: *** Deployment Failed ***
"SimpleStorage" -- Invalid number of parameters for "undefined". Got 2 expected 1!.
at C:\Users\dany.vandermeij\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-deployer\src\deployment.js:364:1
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
Truffle v5.0.1 (core: 5.0.1)
Node v8.11.4
When I don't add the "privateFor" parameter, it works:
var SimpleStorage = artifacts.require("SimpleStorage");
module.exports = function(deployer) {
deployer.deploy(SimpleStorage, 42)
};
But I need this privateFor parameter..
Does someone know how to fix this?
Hey #BlockChainProgrammer. Thanks for guiding me on how to use the Quorum proxy. It worked.
For this error, Try to upgrade/downgrade your truffle version to v4.1.
$ npm install -g truffle#4.1.10
and change the version of solidity to 0.4.24 in your truffle-config.js and the SimpleStorage.sol and add back privateFor in your migration file.
In this case of quorum, the
{
privateFor: ["ROAZBWtSacxXQrOe3FGAqJDyJjFePR5ce4TSIzmJ0Bc="]})
};
was not defined in the contract, and at such the error, but that particular truffle compiler is compatible with Quorum features.
But For non-Quorum users like myself
The error Usually means, define a variable in your contract and not a compiler problem. Most likely a parameter not set in the constructor.
Open to corrections
Problem solved!
What I had to do is to downgrade truffle to "4.1.10" with:
truffle uninstall -g
and then
npm install -g truffle#4.1.10
Many thanks to #TS28

Unable to run truffle#2.1.2 migrate --network live. "Exceeds block gas limit"

I am using truffle#2.1.2 to deploy smart contracts against a localhost:8545 geth#1.5.9-stable rpc, using an account that is funded with Ether has been unlocked using personal.unlockAccount on the geth console.
I have also tried the same against a remote Parity node via RPC, but this is the latest which I am rather stuck with.
truffle.js
module.exports = {
build: {
"index.html": "index.html",
"app.js": [
"javascripts/app.js"
],
"app.css": [
"stylesheets/app.css"
],
"images/": "images/"
},
rpc: {
host: "localhost",
port: 8545
},
networks: {
"ropsten": {
network_id: 3,
port: 8548, // ssh tunnelled to AWS geth/parity node localhost:8545
from: "0x4f000Bcf4641E2fDcE85BF26A694b053996850D4"
},
"live": {
network_id: 1,
port: 8545,
from: "0x00269400181f1B379784BD8cDF786bb20e91Bdef",
gas: 4612388,
gasPrice: 2776297000 // taken from Parity startup log message "Updated conversion rate to Ξ1 = US$42.88 (2776297000 wei/gas)"
}
}
};
truffle migrate --network live
Running migration: 1_initial_migration.js
Deploying Migrations...
Error encountered, bailing. Network state unknown. Review successful transactions manually.
Error: Exceeds block gas limit
at Object.module.exports.InvalidResponse (/home/ubuntu/.nvm/versions/node/v6.2.1/lib/node_modules/truffle/node_modules/ether-pudding/node_modules/web3/lib/web3/errors.js:35:16)
at /home/ubuntu/.nvm/versions/node/v6.2.1/lib/node_modules/truffle/node_modules/ether-pudding/node_modules/web3/lib/web3/requestmanager.js:86:36
at request.onreadystatechange (/home/ubuntu/.nvm/versions/node/v6.2.1/lib/node_modules/truffle/node_modules/web3/lib/web3/httpprovider.js:114:13)
at dispatchEvent (/home/ubuntu/.nvm/versions/node/v6.2.1/lib/node_modules/truffle/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:591:25)
at setState (/home/ubuntu/.nvm/versions/node/v6.2.1/lib/node_modules/truffle/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:610:14)
at IncomingMessage.<anonymous> (/home/ubuntu/.nvm/versions/node/v6.2.1/lib/node_modules/truffle/node_modules/xmlhttprequest/lib/XMLHttpRequest.js:447:13)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:926:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)
I have tried adjusting gas and gasPrice, but am unable to find values that have any affect.
How can I solve this problem, or are there alternative contract deployment methods I should look into?
Kind Regards.
I was able to solve this by simply setting gas: 3000000 in the network config.
"live": {
network_id: 1,
port: 8545,
from: "0x00269400181f1B379784BD8cDF786bb20e91Bdef",
gas: 3000000
}
It cost about 0.5 ETH to run migrations and took several minutes.
In my case the problem was generated by a user's empty balance.
so check your balances using the following function :
function checkAllBalances() {
var totalBal = 0;
for (var acctNum in eth.accounts) {
var acct = eth.accounts[acctNum];
var acctBal = web3.fromWei(eth.getBalance(acct), "ether");
totalBal += parseFloat(acctBal);
console.log(" eth.accounts[" + acctNum + "]: \t" + acct + " \tbalance: " + acctBal + " ether");
}
console.log(" Total balance: " + totalBal + " ether");
};
checkAllBalances();
if the balance is 0 mine some blocks or edit your genesis file.
I solve the same problem by indicate the network id when calling truffle,as:
truffle migrate --network live
and you should modify "from" tag in truffle.js with your unlocked account.
Simple solution: : add gas: 500000 ,(don`t forget to add comma at the last) in truffle.js
module.exports = {
networks: {
development: {
host: "localhost",
port: 8001,
network_id: 1234, // Match any network id
gas: 500000
}
}
};