0

When I try to use this call this method in remix browser it gets mined.

//addAsset function adds an asset along with an owner
    function addAsset(address newOwner,bytes32 description, uint cost) returns(string) {
        if (msg.sender == issuer) {
            assetCount++;
            Asset memory tempAsset = Asset(assetCount,newOwner,description,cost);
            setAssetOwnership(newOwner,assetCount,tempAsset);
            return "asset created";
    } else { 
        return "you are not the owner of contract";
    }
    }

But when I call the same method in the browser via web3 object, I get this.

VM exception out of gas error

    <script>
    if (typeof web3 !== 'undefined') {
        var web3 = new Web3(web3.currentProvider);
        } 
        else 
        {
            // set the provider you want from Web3.providers
            var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
        }                 

        console.log(web3);

        web3.eth.defaultAccount = web3.eth.accounts[0];
        var vishContract = web3.eth.contract(CONTRACT-OPCODE);

//trying to increase the gas limit here, not sure if its correct
// var contract = vishContract.at('CONTRACT ADDRESS', {gasLimit: "10000000"}); 
        var contract = vishContract.at('CONTRACT ADDRESS');

        function getIssuerId(){
                 document.getElementById("issuerId").innerText = contract.issuer();
        }
</script>

I saw similar questions posted, most of them were resolved by changing string to bytes32 or it was mentioned that their contract is huge, mine isn't.

I am still fairly new with smart contracts. Can anyone please help me out here?

Thanks in advance :)

2 Answers 2

1

Check if you have sufficient ETH from the account you're calling the contract.

0

Try to use below:

var contract = vishContract.at('CONTRACT ADDRESS', {gas: "10000000"});

instead of

var contract = vishContract.at('CONTRACT ADDRESS', {gasLimit: "10000000"});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.