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

Contract function send does not return the provider error. #2553

Closed
Pogooo opened this issue Mar 21, 2019 · 6 comments · Fixed by #2589
Closed

Contract function send does not return the provider error. #2553

Pogooo opened this issue Mar 21, 2019 · 6 comments · Fixed by #2589
Labels
Bug Addressing a bug

Comments

@Pogooo
Copy link

Pogooo commented Mar 21, 2019

Description

Cannot call contract's methods. I use ERC20 Token transactions in my code and at the contract's send() method the application freezes, but no errors. I would like to ask how should I initialize the contract or the web3 in order to make calls by constractInstance.methods.transfer(address, amount).send();

I saw at the new version, the web3 constructor's Web3ModuleOptions parameter's interface changed, so I picked out from the initialization. Is there an example (that I searched for but unfortunately I didn't find) how should implement the sign() method?

Expected behavior

await this.contractInstance.methods.transfer(addressTo, 10).send({from: addressMain, , gas: 100000, gasPrice: "2000000000"}); should return true (or something)

Actual behavior

At the above instruction the application freezes.

Steps to reproduce the behavior

So here is my code, the first console.log of sendToken() method has input, but after the send has no answer.

import { defaultABI } from "./ERC20DefaultABI";
import { EthereumService } from "../EthereumService";
import { Contract } from 'web3-eth-contract';
import { AbiItem } from 'web3-utils';

export class ERC20Service {

    private contractAddress: string;
    private abi: AbiItem[];
    private ethereumService: EthereumService;
    private tokenName: string;
    private contractInstance: Contract;

    constructor(ethereumService: EthereumService, contractAddress: string, abi: AbiItem[] = null) {
        this.ethereumService = ethereumService;
        this.contractAddress = contractAddress;
        this.abi = abi ? abi : defaultABI;
        this.contractInstance = this.ethereumService.getContractInstance(this.contractAddress, this.abi); //new this.web3.eth.Contract(abi, address);
    }

    public async sendToken() {
        try{
            console.log("The sendToken method called");
            const success = await this.contractInstance.methods.transfer("0x8bFE61d6D375DbCeE8cBaf79799f33AB2973d02c", 10).send({from: "0xb4b00d716e6409Af13574e87647BF6a744f30e7B", gas: 100000, gasPrice: "2000000000"});
            console.log(`The TOKEN successfully sended: ${success}`);
        }
        catch(e) {
            console.log(e);
        }
        // this.tokenName= methods.name();
    }
}

The web3 initialization:

...
this.web3 = new Web3({defaultAccount: mainAddr,
                defaultBlock: "latest",
                defaultGas: 21001,
                defaultGasPrice: "2000000000",
                transactionBlockTimeout: 50,
                transactionConfirmationBlocks: 24,
                transactionPollingTimeout: 480}
                 , undefined);
...

Versions

  • web3.js: 1.0.0-beta.50
  • nodejs: 10.11.0
  • ethereum node: geth 0.20.1
@nivida nivida added the support label Mar 22, 2019
@nivida
Copy link
Contributor

nivida commented Mar 22, 2019

The correct initialization is new Web3(provider, net, options).

@Pogooo
Copy link
Author

Pogooo commented Mar 22, 2019

The connection parameters in the provider was bad. The Ethereum client was on different port, that I gave in the configuration. It turned out when I wanted to unlock my account, and I've got the exception 'Connection is not open on send()', but I didn't get this on contract transaction sending.

@nivida
Copy link
Contributor

nivida commented Mar 22, 2019

Could you add a GitHub repository with your code and development environment? Otherwise, it will be hard to help you. Thanks!

@Pogooo
Copy link
Author

Pogooo commented Mar 22, 2019

I meant the parameter was bad at the web3 initialization with the port number, but I fixed already. I just let information it hasn't exception handling at contract transaction sending, but no problem for me now.

@nivida
Copy link
Contributor

nivida commented Mar 22, 2019

Sorry I've got you wrong. The send and the call method are handled internally the same way. The error should have been thrown there too but I will check that closer asap.

@nivida nivida added Needs Clarification Requires additional input and removed more information needed labels Mar 22, 2019
@nivida nivida changed the title Contract function call/send not works. Contract function send does not return the provider error. Mar 22, 2019
@Pogooo
Copy link
Author

Pogooo commented Mar 22, 2019

More exactly when I change my configuration from HTTP connection (with connection uri: http:127.0.0.1:8545) provider to Websocket provider (with connection uri: ws:127.0.0.1:8545) in Web3 client the contract methods don't have exceptions.

Of course that I mentioned I have simple http connection for the geth but in the code I used websocket provider with websocket provider with ws:127.0.0.1:8545 connection instead of http:127.0.0.1:8545.

@nivida nivida added Bug Addressing a bug and removed Needs Clarification Requires additional input labels Mar 27, 2019
@nivida nivida mentioned this issue Mar 28, 2019
12 tasks
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.

2 participants