Open barakman opened 6 years ago
any updates about web3 in truffle migrate? or is there anyway to use batch request in migrate script?
My workaround for this in my migration scripts:
const Web3 = require('web3')
const { networks } = require('../truffle-config.js')
module.exports = async (deployer, network) => {
if ('development' === network) {
const { provider } = (networks[network] || {})
if (!provider) {
throw new Error(`Unable to find provider for network: ${network}`)
}
const web3 = new Web3(provider)
// do stuff with web3 instance
}
}
Note: using truffle@5.0.28, web3@1.0.0-beta33
it is work for me using Truffle v5.1.46
:
const Migrations = artifacts.require("Migrations");
module.exports = async function (deployer, network, accounts) {
var adapter = Migrations.interfaceAdapter;
const web3 = adapter.web3;
const provider = web3.currentProvider
}
Here is what the doc says:
This is indeed the case for a JS file which is used as input to
truffle test
.But using the same file as (implicit) input to
truffle migrate
gives:You may ask yourselves, when would the same file be used for both
truffle test
andtruffle migrate
?Well, for example, I need to initialize a large database (3-dimensional array).
I need this both for testing and for the actual deployment.
Adding
let web3 = require("web3")
in the file doesn't seem appropriate (because it is not necessarily necessary).I believe that
truffle test
andtruffle migrate
should behave identically on this aspect.Thanks