Error: Error: Expected parameter 'from' not passed to function.
EVM/moonbeam_doc/Using with Truffle/TruffleTest/MetaCoin$ truffle migrate
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
Error: Expected parameter 'from' not passed to function.
at has (/usr/local/lib/node_modules/truffle/build/webpack:/packages/expect/dist/src/index.js:10:1)
at Object.options (/usr/local/lib/node_modules/truffle/build/webpack:/packages/expect/dist/src/index.js:19:1)
at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:65:1)
at runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:258:1)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:223:1)
at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:172:1)
Truffle v5.4.3 (core: 5.4.3)
Node v14.15.5
Solution:
add the: from parameter in trufle-config.js to indicate which account is in the deployment contract
before adding:
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 9933,
network_id: "*",
}
}
};
After adding:
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 9933,
network_id: "*",
from: "0x6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b",
}
}
};
0x6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b
It’s the node’s built-in ethereum account.
Deploy again: truffle migrate, error reported:no signer available.
EVM/moonbeam_doc/Using with Truffle/TruffleTest/MetaCoin$ truffle migrate
Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.
Starting migrations...
======================
> Network name: 'development'
> Network id: 1281
> Block gas limit: 15000000 (0xe4e1c0)
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
Error: *** Deployment Failed ***
"Migrations" -- Returned error: no signer available.
at /usr/local/lib/node_modules/truffle/build/webpack:/packages/deployer/src/deployment.js:365:1
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at Migration._deploy (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:70:1)
at Migration._load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:56:1)
at Migration.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:217:1)
at Object.runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:150:1)
at Object.runFrom (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:110:1)
at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:87:1)
at runMigrations (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:258:1)
at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate.js:223:1)
at Command.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:172:1)
Truffle v5.4.3 (core: 5.4.3)
Node v14.15.5
View account
enter the truss console first:
truffle console
Default account:
The truss migrate command runs the migration footprint deployment contract.
Which account is used when executing truss migrate
web3.eth.defaultaccount – default account
The web3.eth.defaultaccount attribute records the default address. If the from
attribute is not specified in the following method, the value of the web3.eth.defaultaccount attribute will be used as the default from attribute value.
web3.eth.sendTransaction()web3.eth.call()new web3.eth.Contract() -> myContract.methods.myMethod().call()new web3.eth.Contract() -> myContract.methods.myMethod().send()
Call:
web3.eth.defaultAccount
Attribute:
string
– 20 bytes: Ethereum address. You should save the private key of the address in the node or keystore. The default value is undefined
Example code:
web3.eth.defaultAccount;
> undefined
// set the default account
web3.eth.defaultAccount = '0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe';
Ganache cli has 10 preset accounts, and truss migrate uses the first preset account for deployment contracts by default.
truss migrate
What did you do
///truffle/packages/core/lib/commands/deploy.js
const migrate = require("./migrate");
const command = {
command: "deploy",
description: "(alias for migrate)",
builder: migrate.builder,
help: {
usage:
"truffle deploy [--reset] [-f <number>] [--compile-all] [--verbose-rpc]",
options: migrate.help.options,
allowedGlobalOptions: ["network", "config"]
},
run: migrate.run
};
module.exports = command;
Call the deploy() function:
//truffle/packages/contract/lib/execute.js
/**
* Deploys an instance
* @param {Object} constructorABI Constructor ABI segment w/ inputs & outputs keys
* @return {PromiEvent} Resolves a TruffleContract instance
*/
deploy: function (constructorABI) {
const constructor = this;
const web3 = constructor.web3;
return function () {
let deferred;
const promiEvent = new PromiEvent(false, constructor.debugger, true);
execute
.prepareCall(constructor, constructorABI, arguments)
.then(async ({ args, params, network }) => {
const { blockLimit } = network;
utils.checkLibraries.apply(constructor);
// Promievent and flag that allows instance to resolve (rather than just receipt)
const context = {
contract: constructor,
promiEvent,
onlyEmitReceipt: true
};
const options = {
data: constructor.binary,
arguments: args
};
const contract = new web3.eth.Contract(constructor.abi);
params.data = contract.deploy(options).encodeABI();
params.gas = await execute.getGasEstimate.call(
constructor,
params,
blockLimit
);
context.params = params;
promiEvent.eventEmitter.emit("execute:deploy:method", {
args,
abi: constructorABI,
contract: constructor
});
deferred = execute.sendTransaction(web3, params, promiEvent, context); //the crazy things we do for stacktracing...
try {
const receipt = await deferred;
if (receipt.status !== undefined && !receipt.status) {
const reason = await Reason.get(params, web3);
const error = new StatusError(
params,
context.transactionHash,
receipt,
reason
);
return context.promiEvent.reject(error);
}
const web3Instance = new web3.eth.Contract(
constructor.abi,
receipt.contractAddress
);
web3Instance.transactionHash = context.transactionHash;
context.promiEvent.resolve(new constructor(web3Instance));
} catch (web3Error) {
// Manage web3's 50 blocks' timeout error.
// Web3's own subscriptions go dead here.
await override.start.call(constructor, context, web3Error);
}
})
.catch(promiEvent.reject);
return promiEvent.eventEmitter;
};
},
Preparecall() function:
/**
* Prepares simple wrapped calls by checking network and organizing the method inputs into
* objects web3 can consume.
* @param {Object} constructor TruffleContract constructor
* @param {Object} methodABI Function ABI segment w/ inputs & outputs keys.
* @param {Array} _arguments Arguments passed to method invocation
* @return {Promise} Resolves object w/ tx params disambiguated from arguments
*/
prepareCall: async function (constructor, methodABI, _arguments) {
let args = Array.prototype.slice.call(_arguments);
let params = utils.getTxParams.call(constructor, methodABI, args);
args = utils.convertToEthersBN(args);
if (constructor.ens && constructor.ens.enabled) {
const { web3 } = constructor;
const processedValues = await utils.ens.convertENSNames({
networkId: constructor.network_id,
ensSettings: constructor.ens,
inputArgs: args,
inputParams: params,
methodABI,
web3
});
args = processedValues.args;
params = processedValues.params;
}
const network = await constructor.detectNetwork();
return { args, params, network };
},
Sendtransaction() function
//our own custom sendTransaction function, made to mimic web3's,
//while also being able to do things, like, say, store the transaction
//hash even in case of failure. it's not as powerful in some ways,
//as it just returns an ordinary Promise rather than web3's PromiEvent,
//but it's more suited to our purposes (we're not using that PromiEvent
//functionality here anyway)
//input works the same as input to web3.sendTransaction
//(well, OK, it's lacking some things there too, but again, good enough
//for our purposes)
sendTransaction: async function (web3, params, promiEvent, context) {
//if we don't need the debugger, let's not risk any errors on our part,
//and just have web3 do everything
if (!promiEvent || !promiEvent.debug) {
const deferred = web3.eth.sendTransaction(params);
handlers.setup(deferred, context);
return deferred;
}
//otherwise, do things manually!
//(and skip the PromiEvent stuff :-/ )
return sendTransactionManual(web3, params, promiEvent);
}
Compare and analyze how the deployment script deploy.js calls the web3.js interface to deploy a contract:
//filename: deploy.js
const Web3 = require('web3');
const contractFile = require('./compile');
/*
-- Define Provider & Variables --
*/
// Provider
const providerRPC = {
development: 'http://localhost:8545',
};
const web3 = new Web3(providerRPC.development); //Change to correct network
// Variables
const account_from = {
privateKey: 'YOUR-PRIVATE-KEY-HERE',
address: 'PUBLIC-ADDRESS-OF-PK-HERE',
};
const bytecode = contractFile.evm.bytecode.object;
const abi = contractFile.abi;
/*
-- Deploy Contract --
*/
const deploy = async () => {
console.log(`Attempting to deploy from account ${account_from.address}`);
// Create Contract Instance
const incrementer = new web3.eth.Contract(abi);
// Create Constructor Tx
const incrementerTx = incrementer.deploy({
data: bytecode,
arguments: [5],
});
// Sign Transacation and Send
const createTransaction = await web3.eth.accounts.signTransaction(
{
data: incrementerTx.encodeABI(),
gas: await incrementerTx.estimateGas(),
},
account_from.privateKey
);
// Send Tx and Wait for Receipt
const createReceipt = await web3.eth.sendSignedTransaction(
createTransaction.rawTransaction
);
console.log(
`Contract deployed at address: ${createReceipt.contractAddress}`
);
};
deploy();
Will the slave account be involved in calling the RPC interface of Ethereum to initiate a deployment contract
What does moonbeam’s truss box do to make it compatible with truss migrate
Related contents:
https://www.trufflesuite.com/docs/truffle/getting-started/interacting-with-your-contracts
Truffle/NPM error “expected parameter ‘from’ not passed to function”
truffle practice
Default truffle project gives’ expected parameter ‘from’ not passed to function. ‘error after’ truffle migrate ‘command #548
Explain truffle migrations in detail – contract deployment is no longer confused
Ethereum development learning notes – truffle migrate
Read More:
- How to Solve failed Precondition Error: attempting to use uninitialized value beta1_power
- C#: How to Use Httpclient to upload files with other parameters
- How to use C # to get image format without system. Drawing. Common
- React bootstrap loading and how to use modules
- How to Use qdbusinterface to call DBUS interface
- Using onnx to deploy models in mmdetection
- How to use matlab to solve equation
- How to use vimdiff to solve conflict?
- Tensorflow: How to use expand_Dim() to add dimensions
- How to use Latex to Write Matrices
- How to Use paho.mqtt.cpp
- How to Use spatial in MAC
- How to use C + + function pointer array
- Deploy mongodb fragment combined with replica set to realize distributed storage of MySQL database files (step 10)
- How to use scanner to accept char type characters in Java
- How to Use the Reverse() Function
- How to use high version OpenGL under Windows
- tf.one_ How to use hot ()
- How to Use ffmpeg to convert MP4 and other formats to MP3 format
- How to solve oserror: [errno 98] address already in use and kill the python3 process