Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send transaction to smart contract don't parse "from" option #2341

Closed
maroodb opened this issue Feb 7, 2019 · 7 comments · Fixed by #2393
Closed

Send transaction to smart contract don't parse "from" option #2341

maroodb opened this issue Feb 7, 2019 · 7 comments · Fixed by #2393
Labels
Bug Addressing a bug

Comments

@maroodb
Copy link

maroodb commented Feb 7, 2019

Expected behavior

Send transaction to smart contract method

Actual behavior

Throws a strange error

Steps to reproduce the behavior

const contractInstance = new web3.eth.Contract(abi,address );
 return new Promise((resolve, reject) => {
            contractInstance .methods.addData(data).send({ from: "0x3b0282D31174B927e102bA71d80dF34F4e596Fc4", gas:300000},(error, result) => {
                if (!error) {
                    resolve(result)
                } else {
                    reject(error);
                }
            })
        })

Error Logs

`TypeError: Cannot create property 'from' on string '0xf9056d808509502f9000830493e09439126b2a8801909a7b379e503c5ee270ff700e0580b905043a03cbec0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000240000000000000000000000000000000000000000000000000000000000000028000000000000000000000000000000000000000000000000000000000000002c000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000340000000000000000000000000000000000000000000000000000000000000038000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000440000000000000000000000000000000000000000000000000000000000000001044442d313534393535393330313536320000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000074d61726f75656e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000644626f75626100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006504153503031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000073033313435363400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000653454a3031320000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000354554e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e4d454c4c49544120444a4552424100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000034652410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a30332d30372d3230313700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c627572656175456e747265650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c9000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000034555520000000000000000000000000000000000000000000000000000000000820bfaa06b1d4370a2ab603dbf83b51c342643bff86a997b2ffbd24877a1dda7a8623a46a05ead679cbd26ed8f4353e1aeb4df24290334fbb0a7caed20dd81bdef96735c0e'

`

Versions

npm v6.4.1
node v10.13.0
web3js v1.0.0-beta.41
OS windows 10

@nivida
Copy link
Contributor

nivida commented Feb 7, 2019

Could you add the complete code example? thanks :)

@maroodb
Copy link
Author

maroodb commented Feb 8, 2019

This is a complete example, the instance is created in an other class ,
NB: getData works fine!

const abi = [] // [..] abi of contract
const address = "0x39126b2a8801909a7b379e503c5ee270ff700e05";

class MyContract {

    constructor (web3) {
        this.instance = new web3.eth.Contract(abi,address);
    }


    getData (ref) {
        return this.instance.methods.getData(ref).call()
    }


    setData (data) {
        return new Promise((resolve, reject) => {
            this.instance.methods.setData(data).send({from: "0x3b0282D31174B927e102bA71d80dF34F4e596Fc4", gas:300000},(error, result) => {
                if (!error) {
                    resolve(result)
                } else {
                    reject(error);
                }
            })

        })
    }
}

module.exports = MyContract;

This class Web3API that provide web3 instance and add accounts:

const Web3 = require('web3');

class Web3API {

    constructor() {
        this.web3 =  new Web3(new Web3.providers.WebsocketProvider('ws://localhost:3000'))
    }

      getInstance() {
        return this.web3;
    }

    addAccountToWallet (account) {
        this.web3.eth.accounts.wallet.add(account);
    }


}

// default account
const instance = new Web3API();
const privateKey = '0xb10dffbae01f7caeb15465daa0cd4110e363e5fc0e88e10bf214a9a367d19e49';
let account = instance.web3.eth.accounts.privateKeyToAccount(privateKey);
instance.addAccountToWallet(account);

module.exports = instance;

And this is the main class:

const Web3API = require('./Web3API');
const MyContract = require('./MyContract');

const web3 = Web3API.getInstance();
const myContract = new MyContract(web3);

myContract.getData("01").then(console.log) // it works!

myContract.setData({some: "json data"}).then(console.log).catch(console.log)// it throws the error

@maroodb
Copy link
Author

maroodb commented Feb 8, 2019

The same code works with web3js v1.0.0-beta.37

@nivida nivida added Needs Clarification Requires additional input and removed more information needed labels Feb 10, 2019
@haozileung
Copy link

same error in 1.0.0-beta.46
weird...

@leonprou
Copy link
Contributor

I debugged this issue and found some inconsistency in types of web3-core-method.

The execute function puts rawTransaction into parameters here, but in beforeExecution, the inputTransactionFormatter accepts to receive a txObject. Not sure it needs to call the beforeExecution at all.
FYI @nivida

@nivida nivida added Bug Addressing a bug and removed Needs Clarification Requires additional input labels Feb 19, 2019
@nivida nivida mentioned this issue Feb 19, 2019
12 tasks
@karankurbur
Copy link

karankurbur commented Feb 19, 2019

same error on 1.0.0-beta.46
downgraded to 1.0.0-beta.37 and it works

@sydneyitguy
Copy link

sydneyitguy commented Mar 5, 2019

I guess this code has merged into web3.js 1.0.0-beta.47 incorrectly (maybe the fix has overwritten by #2367).
The same problem happens on web3.js 1.0.0-beta.47

-- updated --
Oh I just tried putting defaultOptions on send(defaultOptions) instead of Contract(abi, network, defaultOptions) and that worked.
It seems #2393 fixed the issue on send() function, but not on Contract constructor.

-- updated --
now it stuck with a bug: #2447 lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Addressing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants