我与 Ganache 和 nodeJS 一起工作。每当我努力使用 JavaScript 部署我的合约时,都会挖掘相关块,这表明给定的合约已部署,但发送者帐户(或部署者帐户)的余额不会更新。我可以看到有什么问题。
JavaScript 代码:
const Web3 = require("web3");
web3 = new Web3(new Web3.providers.HttpProvider(Web3.currentProvider));
.
.
.
const cid = <a value>;
const pid = <a value>;
const source2='path of my solidity file';
const compiledMyContract = solc.compile(source2);
const myContractJson="path of json version of my solidity file";
const myContractJs = JSON.parse(fs.readFileSync(myContractJson));
const contractByteCode="...";
const gasEstimate = await web3.eth.estimateGas({data: contractByteCode});
const myContract = new web3.eth.Contract(myContractJs.abi, null, {data: contractByteCode});
myContract.deploy().send({from:<address>, gas: gasEstimate, gasPrice:
200}).then((instance) => {
console.log("Contract mined at " + instance.options.address);
instance.methods.function_A(cid, pid).send({
from:<address>,
gas: 2000000,
gasPrice: 200
});
.
.
.