Cannot create property 'from' on string

by klautern   Last Updated February 27, 2019 08:28 AM

I'm trying to call a contract method from web3js. The contract is deployed in a local ganache. This is my full code

// Instantiate contract
const provider = new Web3.providers.HttpProvider("http://127.0.0.1:7545");
const web3 = new Web3(provider);
const contract = new web3.eth.Contract(conf.contract.abi, "0x...", { gasPrice: 1, gas: 4500000 });

// Import account and add to wallet
const account = web3.eth.accounts.privateKeyToAccount("0x...");
web3.eth.accounts.wallet.add(account);

// Estimate gas
var estimatedGas  = await contract.methods.createRecord().estimateGas({ from: account.address });
var gasPrice = 1;
var requiredGas = estimatedGas * gasPrice;

// Call contract method: ERROR
var result = await contract.methods.createRecord().send({ from: account.address, gas: requiredGas });

The last line raises this error

TypeError: Cannot create property 'from' on string '0xf90247800182fbd8947167868c5e3161d9e6d0d8be564f05a432b02f5e80b901e45170f1fa00000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e00000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001a0000000000000000000000000000000000000000000000000000000000000000b736572766572312e636f6d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007312e302e302e310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000093137322e302e302e31000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000074d4143303030310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020111000000000000000000000000000000000000000000000000000000000000822d45a042ba0d363180c9ca85a10fe919536909e2ca78f0e5dd3409c43db902c85ac09ba024c54001ace92edf9438fc91cbef70b7caf5aeba68f8048b39a1018c3fc47fe5'
    at Object.inputTransactionFormatter (d:\Users\107596\Documents\Proyectos\ethereum\jakin-code-daia\js\node_modules\web3-core-helpers\dist\web3-core-helpers.cjs.js:78:21)
    at SendContractMethod.beforeExecution (d:\Users\107596\Documents\Proyectos\ethereum\jakin-code-daia\js\node_modules\web3-core-method\dist\web3-core-method.cjs.js:1075:44)
    at SendContractMethod.execute (d:\Users\107596\Documents\Proyectos\ethereum\jakin-code-daia\js\node_modules\web3-core-method\dist\web3-core-method.cjs.js:1006:12)
    at d:\Users\107596\Documents\Proyectos\ethereum\jakin-code-daia\js\node_modules\web3-core-method\dist\web3-core-method.cjs.js:1100:85
    at process._tickCallback (internal/process/next_tick.js:68:7)

Any clue about the error? I've got very similar code running ok in other projects, but here there seems to be something wrong and I can't find it.

Thanks

Tags : web3js ganache


Related Questions


Updated March 25, 2019 23:28 PM

Updated February 14, 2019 22:28 PM

Updated May 22, 2018 12:28 PM

Updated June 16, 2018 01:28 AM