4

In this course while deploying the first contract on rinkby network.It's not working for me as it throws an error Error: transaction underpriced

Below is the code which I tried to deploy

File: deploy.js

const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const {interface, bytecode} = require('./compile');

const provider = new HDWalletProvider(
    'melody fee rough pond kit insane trumpet section jewel stable deal make',
    'https://rinkeby.infura.io/v3/1d4b424061734af684e16f68ab928c88',);

const web3 = new Web3(provider);

const deploy = async() => {
    const accouts = await web3.eth.getAccounts();
    console.log('Attempting to deploy from account', accouts[0]);

    const result = await new web3.eth.Contract(JSON.parse(interface))
        .deploy({data: bytecode, arguments: ['Hi there!']})
        .send({gas: '1000000', from: accouts[0]});

    console.log('Contract deployed to', result.options.address);
};
deploy();

Following is the error which I got:

    Attempting to deploy from account 0x2d284659C5022543B7a4eFfC19015Bd92adeB845
Error: transaction underpriced
    at C:\Users\91960\inbox\node_modules\web3-provider-engine\subproviders\web3.js:15:44
    at XMLHttpRequest.request.onreadystatechange 

What is the required value of gas parameter for deploying the contract?

UPDATE

I updated the required line of code : .send({gas: '2000000000', from: accouts[0]});

This is the error I got:

`

Attempting to deploy from account 0x2d284659C5022543B7a4eFfC19015Bd92adeB845
Error: exceeds block gas limit
    at C:\Users\91960\inbox\node_modules\web3-provider-engine\subproviders\web3.js:15:44
    at XMLHttpRequest.request.onreadystatechange (C:\Users\91960\inbox\node_modules\truffle-hdwallet-provider\node_modules\web3\lib\web3\httpprovider.js:118:13)
    at XMLHttpRequest.dispatchEvent (C:\Users\91960\inbox\node_modules\xhr2\lib\xhr2.js:76:20)
    at XMLHttpRequest._setReadyState (C:\Users\91960\inbox\node_modules\xhr2\lib\xhr2.js:422:14)
    at XMLHttpRequest._onHttpResponseEnd (C:\Users\91960\inbox\node_modules\xhr2\lib\xhr2.js:616:14)
    at IncomingMessage.<anonymous> (C:\Users\91960\inbox\node_modules\xhr2\lib\xhr2.js:568:23)
    at IncomingMessage.emit (node:events:402:35)
    at endReadableNT (node:internal/streams/readable:1343:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
Error: exceeds block gas limit
    at C:\Users\91960\inbox\node_modules\web3-provider-engine\subproviders\web3.js:15:44
    at XMLHttpRequest.request.onreadystatechange (C:\Users\91960\inbox\node_modules\truffle-hdwallet-provider\node_modules\web3\lib\web3\httpprovider.js:118:13)
    at XMLHttpRequest.dispatchEvent (C:\Users\91960\inbox\node_modules\xhr2\lib\xhr2.js:76:20)
    at XMLHttpRequest._setReadyState (C:\Users\91960\inbox\node_modules\xhr2\lib\xhr2.js:422:14)
    at XMLHttpRequest._onHttpResponseEnd (C:\Users\91960\inbox\node_modules\xhr2\lib\xhr2.js:616:14)
    at IncomingMessage.<anonymous> (C:\Users\91960\inbox\node_modules\xhr2\lib\xhr2.js:568:23)
    at IncomingMessage.emit (node:events:402:35)
    at endReadableNT (node:internal/streams/readable:1343:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)

C:\Users\91960\inbox\node_modules\solc\soljson.js:24
(Module.asmGlobalArg,Module.asmLibraryArg,buffer);var __GLOBAL__sub_I_ABIFunctions_cpp=Module["__GLOBAL__sub_I_ABIFunctions_cpp"]=asm["__GLOBAL__sub_I_ABIFunctions_cpp"];var __GLOBAL__sub_I_ABI_cpp=Module["__GLOBAL__sub_I_ABI_cpp"]=asm["__GLOBAL__sub_I_ABI_cpp"];var __GLOBAL__sub_I_ASTJsonConverter_cpp=Module["__GLOBAL__sub_I_ASTJsonConverter_cpp"]=asm["__GLOBAL__sub_I_ASTJsonConverter_cpp"];var __GLOBAL__sub_I_AST_cpp=Module["__GLOBAL__sub_I_AST_cpp"]=asm["__GLOBAL__sub_I_AST_cpp"];var __GLOBAL__sub_I_ArrayUtils_cpp=Module["__GLOBAL__sub_I_ArrayUtils_cpp"]=asm["__GLOBAL__sub_I_ArrayUtils_cpp"];var __GLOBAL__sub_I_AsmAnalysis_cpp=Module["__GLOBAL__sub_I_AsmAnalysis_cpp"]=asm["__GLOBAL__sub_I_AsmAnalysis_cpp"];var __GLOBAL__sub_I_CompilerContext_cpp=Module["__GLOBAL__sub_I_CompilerContext_cpp"]=asm["__GLOBAL__sub_I_CompilerContext_cpp"];var __GLOBAL__sub_I_CompilerStack_cpp=Module["__GLOBAL__sub_I_CompilerStack_cpp"]=asm["__GLOBAL__sub_I_CompilerStack_cpp"];var __GLOBAL__sub_I_CompilerUtils_cpp=Module["__GLOBAL__sub_I_CompilerUtils_cpp"]=asm["__GLOBAL__sub_I_CompilerUtils_cpp"];var __GLOBAL__sub_I_Compiler_cpp=Module["__GLOBAL__sub_I_Compiler_cpp"]=asm["__GLOBAL__sub_I_Compiler_cpp"];var __GLOBAL__sub_I_ConstantEvaluator_cpp=Module["__GLOBAL__sub_I_ConstantEvaluator_cpp"]=asm["__GLOBAL__sub_I_ConstantEvaluator_cpp"];var __GLOBAL__sub_I_ContractCompiler_cpp=Module["__GLOBAL__sub_I_ContractCompiler_cpp"]=asm["__GLOBAL__sub_I_ContractCompiler_cpp"];var __GLOBAL__sub_I_ControlFlowAnalyzer_cpp=Module["__GLOBAL__sub_I_ControlFlowAnalyzer_cpp"]=asm["__GLOBAL__sub_I_ControlFlowAnalyzer_cpp"];var __GLOBAL__sub_I_ControlFlowBuilder_cpp=Module["__GLOBAL__sub_I_ControlFlowBuilder_cpp"]=asm["__GLOBAL__sub_I_ControlFlowBuilder_cpp"];var __GLOBAL__sub_I_ControlFlowGraph_cpp=Module["__GLOBAL__sub_I_ControlFlowGraph_cpp"]=asm["__GLOBAL__sub_I_ControlFlowGraph_cpp"];var __GLOBAL__sub_I_DeclarationContainer_cpp=Module["__GLOBAL__sub_I_DeclarationContainer_cpp"]=asm["__GLOBAL__sub_I_DeclarationContainer_cpp"];var __GLOBAL__sub_I_DocStringAnalyser_cpp=Module["__GLOBAL__sub_I_DocStringAnalyser_cpp"]=asm["__GLOBAL__sub_I_DocStringAnalyser_cpp"];var __GLOBAL__sub_I_DocStringParser_cpp=Module["__GLOBAL__sub_I_DocStringParser_cpp"]=asm["__GLOBAL__sub_I_DocStringParser_cpp"];var __GLOBAL__sub_I_ErrorReporter_cpp=Module["__GLOBAL__sub_I_ErrorReporter_cpp"]=asm["__GLOBAL__sub_I_ErrorReporter_cpp"];var __GLOBAL__sub_I_ExpressionCompiler_cpp=Module["__GLOBAL__sub_I_ExpressionCompiler_cpp"]=asm["__GLOBAL__sub_I_ExpressionCompiler_cpp"];var __GLOBAL__sub_I_GasEstimator_cpp=Module["__GLOBAL__sub_I_GasEstimator_cpp"]=asm["__GLOBAL__sub_I_GasEstimator_cpp"];var __GLOBAL__sub_I_GlobalContext_cpp=Module["__GLOBAL__sub_I_GlobalContext_cpp"]=asm["__GLOBAL__sub_I_GlobalContext_cpp"];var __GLOBAL__sub_I_Instruction_cpp=Module["__GLOBAL__sub_I_Instruction_cpp"]=asm["__GLOBAL__sub_I_Instruction_cpp"];var __GLOBAL__sub_I_LValue_cpp=Module["__GLOBAL__sub_I_LValue_cpp"]=asm["__GLOBAL__sub_I_LValue_cpp"];var __GLOBAL__sub_I_NameAndTypeResolver_cpp=Module["__GLOBAL__sub_I_NameAndTypeResolver_cpp"]=asm["__GLOBAL__sub_I_NameAndTypeResolver_cpp"];var __GLOBAL__sub_I_Natspec_cpp=Module["__GLOBAL__sub_I_Natspec_cpp"]=asm["__GLOBAL__sub_I_Natspec_cpp"];var __GLOBAL__sub_I_Parser_cpp=Module["__GLOBAL__sub_I_Parser_cpp"]=asm["__GLOBAL__sub_I_Parser_cpp"];var __GLOBAL__sub_I_PostTypeChecker_cpp=Module["__GLOBAL__sub_I_PostTypeChecker_cpp"]=asm["__GLOBAL__sub_I_PostTypeChecker_cpp"];var __GLOBAL__sub_I_ReferencesResolver_cpp=Module["__GLOBAL__sub_I_ReferencesResolver_cpp"]=asm["__GLOBAL__sub_I_ReferencesResolver_cpp"];var __GLOBAL__sub_I_SMTChecker_cpp=Module["__GLOBAL__sub_I_SMTChecker_cpp"]=asm["__GLOBAL__sub_I_SMTChecker_cpp"];var __GLOBAL__sub_I_SSAVariable_cpp=Module["__GLOBAL__sub_I_SSAVariable_cpp"]=asm["__GLOBAL__sub_I_SSAVariable_cpp"];var __GLOBAL__sub_I_StandardCompiler_cpp=Module["__GLOBAL__sub_I_StandardCompiler_cpp"]=asm["__GLOBAL__sub_I_StandardCompiler_cpp"];var __GLOBAL__sub_I_StaticAnalyzer_cpp=Module["__GLOBAL__sub_I_StaticAnalyzer_cpp"]=asm["__GLOBAL__sub_I_StaticAnalyzer_cpp"];var __GLOBAL__sub_I_SymbolicBoolVariable_cpp=Module["__GLOBAL__sub_I_SymbolicBoolVariable_cpp"]=asm["__GLOBAL__sub_I_SymbolicBoolVariable_cpp"];var __GLOBAL__sub_I_SymbolicIntVariable_cpp=Module["__GLOBAL__sub_I_SymbolicIntVariable_cpp"]=asm["__GLOBAL__sub_I_SymbolicIntVariable_cpp"];var __GLOBAL__sub_I_SymbolicVariable_cpp=Module["__GLOBAL__sub_I_SymbolicVariable_cpp"]=asm["__GLOBAL__sub_I_SymbolicVariable_cpp"];var __GLOBAL__sub_I_SyntaxChecker_cpp=Module["__GLOBAL__sub_I_SyntaxChecker_cpp"]=asm["__GLOBAL__sub_I_SyntaxChecker_cpp"];var __GLOBAL__sub_I_TypeChecker_cpp=Module["__GLOBAL__sub_I_TypeChecker_cpp"]=asm["__GLOBAL__sub_I_TypeChecker_cpp"];var __GLOBAL__sub_I_Types_cpp=Module["__GLOBAL__sub_I_Types_cpp"]=asm["__GLOBAL__sub_I_Types_cpp"];var __GLOBAL__sub_I_VariableUsage_cpp=Module["__GLOBAL__sub_I_VariableUsage_cpp"]=asm["__GLOBAL__sub_I_VariableUsage_cpp"];var __GLOBAL__sub_I_Version_cpp=Module["__GLOBAL__sub_I_Version_cpp"]=asm["__GLOBAL__sub_I_Version_cpp"];var __GLOBAL__sub_I_ViewPureChecker_cpp=Module["__GLOBAL__sub_I_ViewPureChecker_cpp"]=asm["__GLOBAL__sub_I_ViewPureChecker_cpp"];var __GLOBAL__sub_I_json_value_cpp=Module["__GLOBAL__sub_I_json_value_cpp"]=asm["__GLOBAL__sub_I_json_value_cpp"];var __GLOBAL__sub_I_libsolc_cpp=Module["__GLOBAL__sub_I_libsolc_cpp"]=asm["__GLOBAL__sub_I_libsolc_cpp"];var __ZSt18uncaught_exceptionv=Module["__ZSt18uncaught_exceptionv"]=asm["__ZSt18uncaught_exceptionv"];var ___cxa_can_catch=Module["___cxa_can_catch"]=asm["___cxa_can_catch"];var ___cxa_is_pointer_type=Module["___cxa_is_pointer_type"]=asm["___cxa_is_pointer_type"];var ___cxx_global_var_init_207=Module["___cxx_global_var_init_207"]=asm["___cxx_global_var_init_207"];var ___cxx_global_var_init_6=Module["___cxx_global_var_init_6"]=asm["___cxx_global_var_init_6"];var ___emscripten_environ_constructor=Module["___emscripten_environ_constructor"]=asm["___emscripten_environ_constructor"];var ___muldi3=Module["___muldi3"]=asm["___muldi3"];var ___udivdi3=Module["___udivdi3"]=asm["___udivdi3"];var ___uremdi3=Module["___uremdi3"]=asm["___uremdi3"];var __get_environ=Module["__get_environ"]=asm["__get_environ"];var _bitshift64Lshr=Module["_bitshift64Lshr"]=asm["_bitshift64Lshr"];var _bitshift64Shl=Module["_bitshift64Shl"]=asm["_bitshift64Shl"];var _compileJSON=Module["_compileJSON"]=asm["_compileJSON"];var _compileJSONCallback=Module["_compileJSONCallback"]=asm["_compileJSONCallback"];var _compileJSONMulti=Module["_compileJSONMulti"]=asm["_compileJSONMulti"];var _compileStandard=Module["_compileStandard"]=asm["_compileStandard"];var _emscripten_replace_memory=Module["_emscripten_replace_memory"]=asm["_emscripten_replace_memory"];var _free=Module["_free"]=asm["_free"];var _i64Add=Module["_i64Add"]=asm["_i64Add"];var _i64Subtract=Module["_i64Subtract"]=asm["_i64Subtract"];var _license=Module["_license"]=asm["_license"];var _llvm_bswap_i32=Module["_llvm_bswap_i32"]=asm["_llvm_bswap_i32"];var _llvm_cttz_i32=Module["_llvm_cttz_i32"]=asm["_llvm_cttz_i32"];var _malloc=Module["_malloc"]=asm["_malloc"];var _memcpy=Module["_memcpy"]=asm["_memcpy"];var _memmove=Module["_memmove"]=asm["_memmove"];var _memset=Module["_memset"]=asm["_memset"];var _pthread_cond_broadcast=Module["_pthread_cond_broadcast"]=asm["_pthread_cond_broadcast"];var _pthread_mutex_lock=Module["_pthread_mutex_lock"]=asm["_pthread_mutex_lock"];var _pthread_mutex_unlock=Module["_pthread_mutex_unlock"]=asm["_pthread_mutex_unlock"];var _sbrk=Module["_sbrk"]=asm["_sbrk"];var _version=Module["_version"]=asm["_version"];var establishStackSpace=Module["establishStackSpace"]=asm["establishStackSpace"];var setThrew=Module["setThrew"]=asm["setThrew"];var stackAlloc=Module["stackAlloc"]=asm["stackAlloc"];var stackRestore=Module["stackRestore"]=asm["stackRestore"];var stackSave=Module["stackSave"]=asm["stackSave"];var dynCall_diii=Module["dynCall_diii"]=asm["dynCall_diii"];var dynCall_i=Module["dynCall_i"]=asm["dynCall_i"];var dynCall_ii=Module["dynCall_ii"]=asm["dynCall_ii"];var dynCall_iidi=Module["dynCall_iidi"]=asm["dynCall_iidi"];var dynCall_iii=Module["dynCall_iii"]=asm["dynCall_iii"];var dynCall_iiii=Module["dynCall_iiii"]=asm["dynCall_iiii"];var dynCall_iiiii=Module["dynCall_iiiii"]=asm["dynCall_iiiii"];var dynCall_iiiiid=Module["dynCall_iiiiid"]=asm["dynCall_iiiiid"];var dynCall_iiiiii=Module["dynCall_iiiiii"]=asm["dynCall_iiiiii"];var dynCall_iiiiiid=Module["dynCall_iiiiiid"]=asm["dynCall_iiiiiid"];var dynCall_iiiiiii=Module["dynCall_iiiiiii"]=asm["dynCall_iiiiiii"];var dynCall_iiiiiiii=Module["dynCall_iiiiiiii"]=asm["dynCall_iiiiiiii"];var dynCall_iiiiiiiii=Module["dynCall_iiiiiiiii"]=asm["dynCall_iiiiiiiii"];var dynCall_iiiiiiiiiii=Module["dynCall_iiiiiiiiiii"]=asm["dynCall_iiiiiiiiiii"];var dynCall_iiiiiiiiiiii=Module["dynCall_iiiiiiiiiiii"]=asm["dynCall_iiiiiiiiiiii"];var dynCall_iiiiiiiiiiiii=Module["dynCall_iiiiiiiiiiiii"]=asm["dynCall_iiiiiiiiiiiii"];var dynCall_v=Module["dynCall_v"]=asm["dynCall_v"];var dynCall_vi=Module["dynCall_vi"]=asm["dynCall_vi"];var dynCall_vidi=Module["dynCall_vidi"]=asm["dynCall_vidi"];var dynCall_vii=Module["dynCall_vii"]=asm["dynCall_vii"];var dynCall_viii=Module["dynCall_viii"]=asm["dynCall_viii"];var dynCall_viiii=Module["dynCall_viiii"]=asm["dynCall_viiii"];var dynCall_viiiii=Module["dynCall_viiiii"]=asm["dynCall_viiiii"];var dynCall_viiiiii=Module["dynCall_viiiiii"]=asm["dynCall_viiiiii"];var dynCall_viiiiiii=Module["dynCall_viiiiiii"]=asm["dynCall_viiiiiii"];var dynCall_viiiiiiii=Module["dynCall_viiiiiiii"]=asm["dynCall_viiiiiiii"];var dynCall_viiiiiiiii=Module["dynCall_viiiiiiiii"]=asm["dynCall_viiiiiiiii"];var dynCall_viiiiiiiiii=Module["dynCall_viiiiiiiiii"]=asm["dynCall_viiiiiiiiii"];var dynCall_viiiiiiiiiii=Module["dynCall_viiiiiiiiiii"]=asm["dynCall_viiiiiiiiiii"];var dynCall_viiiiiiiiiiii=Module["dynCall_viiiiiiiiiiii"]=asm["dynCall_viiiiiiiiiiii"];var dynCall_viiiiiiiiiiiiiii=Module["dynCall_viiiiiiiiiiiiiii"]=asm["dynCall_viiiiiiiiiiiiiii"];Module["asm"]=asm;Module["cwrap"]=cwrap;Module["setValue"]=setValue;Module["Pointer_stringify"]=Pointer_stringify;Module["stringToUTF8"]=stringToUTF8;Module["lengthBytesUTF8"]=lengthBytesUTF8;Module["addFunction"]=addFunction;Module["removeFunction"]=removeFunction;if(memoryInitializer){if(!isDataURI(memoryInitializer)){memoryInitializer=locateFile(memoryInitializer)}if(ENVIRONMENT_IS_NODE||ENVIRONMENT_IS_SHELL){var data=Module["readBinary"](memoryInitializer);HEAPU8.set(data,GLOBAL_BASE)}else{addRunDependency("memory initializer");var applyMemoryInitializer=(function(data){if(data.byteLength)data=new Uint8Array(data);HEAPU8.set(data,GLOBAL_BASE);if(Module["memoryInitializerRequest"])delete Module["memoryInitializerRequest"].response;removeRunDependency("memory initializer")});function doBrowserLoad(){Module["readAsync"](memoryInitializer,applyMemoryInitializer,(function(){throw"could not load memory initializer "+memoryInitializer}))}var memoryInitializerBytes=tryParseAsDataURI(memoryInitializer);if(memoryInitializerBytes){applyMemoryInitializer(memoryInitializerBytes.buffer)}else if(Module["memoryInitializerRequest"]){function useRequest(){var request=Module["memoryInitializerRequest"];var response=request.response;if(request.status!==200&&request.status!==0){var data=tryParseAsDataURI(Module["memoryInitializerRequestURL"]);if(data){response=data.buffer}else{console.warn("a problem seems to have happened with Module.memoryInitializerRequest, status: "+request.status+", retrying "+memoryInitializer);doBrowserLoad();return}}applyMemoryInitializer(response)}if(Module["memoryInitializerRequest"].response){setTimeout(useRequest,0)}else{Module["memoryInitializerRequest"].addEventListener("load",useRequest)}}else{doBrowserLoad()}}}function ExitStatus(status){this.name="ExitStatus";this.message="Program terminated with exit("+status+")";this.status=status}ExitStatus.prototype=new Error;ExitStatus.prototype.constructor=ExitStatus;dependenciesFulfilled=function runCaller(){if(!Module["calledRun"])run();if(!Module["calledRun"])dependenciesFulfilled=runCaller};function run(args){args=args||Module["arguments"];if(runDependencies>0){return}preRun();if(runDependencies>0)return;if(Module["calledRun"])return;function doRun(){if(Module["calledRun"])return;Module["calledRun"]=true;if(ABORT)return;ensureInitRuntime();preMain();if(Module["onRuntimeInitialized"])Module["onRuntimeInitialized"]();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout((function(){setTimeout((function(){Module["setStatus"]("")}),1);doRun()}),1)}else{doRun()}}Module["run"]=run;function abort(what){if(Module["onAbort"]){Module["onAbort"](what)}if(what!==undefined){out(what);err(what);what=JSON.stringify(what)}else{what=""}ABORT=true;EXITSTATUS=1;throw"abort("+what+"). Build with -s ASSERTIONS=1 for more info."}Module["abort"]=abort;if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}Module["noExitRuntime"]=true;run()
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
abort({}). Build with -s ASSERTIONS=1 for more info.
(Use `node --trace-uncaught ...` to show where the exception was thrown)` `
7
  • Sry my answer was wrong, you need to add -> gasPrice: ‚2000000000‘ inside send({…,
    – Majd TL
    Nov 14, 2021 at 13:21
  • I tried making that change but still it gave an error Error: intrinsic gas too low
    – Anay
    Nov 14, 2021 at 13:33
  • can you updated the questiona and add that updated line in your code and the new error down ?
    – Majd TL
    Nov 14, 2021 at 14:19
  • I have updated the main question...
    – Anay
    Nov 14, 2021 at 16:59
  • No I need to keep gas at it was 1000000 and add additionally the gas price so it will be : .send({gas:‘1000000‘, gasPrice:‘2000000000‘, from: accouts[0]});
    – Majd TL
    Nov 14, 2021 at 20:14

4 Answers 4

4

"Error: transaction underpriced" usually happens when the "gasPrice" you are willing to pay is very low and not accepted by the network.

In your code, you are not setting the "gasPrice" so it will probably 0 or a very low default value. Therefore you need to add that explicitly in WEI (Gas Price on rinkeby is usually between 1 to 5 Gwei)

....
.send({gas:‘1000000‘, gasPrice:‘2000000000‘, from: accouts[0]})
4

I solved this error by manually setting the gas from here: https://polygonscan.com/gastracker I'm deploying to Mumbai testnet. The reason is as stated in the answers the gasPrice is too low.

2

For me resetting my metamask account did the trick. My accounts -> Settings -Advanced -> Reset Account

0

As an addition to the above replies, it could be that the default gas is lower than what miners are accepting at the point of deployment. you could solve this by increasing your gas limit(optional) or just deploying again and this worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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