0

I created a contract (Freight) using the "ratings" tutorial template. The Freight contract is meant to store values entered in the html page (input.html) and submitted. Just like the "ratings" tutorial, though at the moment i get

JavaScript  error   12:49:31    input.html - line 99 - Uncaught ReferenceError: setFreight is not defined

whenever I hit the submit button. How do I solve this?

Link to git repository: https://github.com/Akiiki/Freight.git

3

Couple of things :

-This wont return / do nothing :

function setFreight(string contNumber,
             string s_Invoice,
            string c_Invoice,
            string s_number,
            uint t_Weight,
            uint t_Quantity) {

}

-I don't see where you are requiring web3.js ? You need will need it.

-Where are you instantiating your contract , where is the contract abi ? Where is the contract address ? is your RCP node proprelly configured ?

I feel like your missing this part. so here it is :

Try this :

First inside your browser console deploy using this code :

var freightContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"contNumber","type":"string"},{"name":"s_Invoice","type":"string"},{"name":"c_Invoice","type":"string"},{"name":"s_number","type":"string"},{"name":"t_Weight","type":"uint256"},{"name":"t_Quantity","type":"uint256"}],"name":"setFreight","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"contNumber","type":"string"},{"name":"s_Invoice","type":"string"},{"name":"c_Invoice","type":"string"},{"name":"s_number","type":"string"},{"name":"t_Weight","type":"uint256"},{"name":"t_Quantity","type":"uint256"}],"name":"getFreight","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"type":"function"},{"inputs":[],"type":"constructor"}]);
var freight = freightContract.new(
   {
     from: web3.eth.accounts[0], 
     data: '60606040525b33600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055505b61033a8061003f6000396000f360606040526000357c010000000000000000000000000000000000000000000000000000000090048063124f32bf1461004f5780631a3241b61461018c5780638da5cb5b146102c95761004d565b005b61018a6004808035906020019082018035906020019191908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050909091908035906020019082018035906020019191908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050909091908035906020019082018035906020019191908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050909091908035906020019082018035906020019191908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050909091908035906020019091908035906020019091905050610328565b005b6102c76004808035906020019082018035906020019191908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050909091908035906020019082018035906020019191908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050909091908035906020019082018035906020019191908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050909091908035906020019082018035906020019191908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050909091908035906020019091908035906020019091905050610331565b005b6102d66004805050610302565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b5b505050505050565b5b50505050505056', 
     gas: 3000000
   }, function(e, contract){
    console.log(e, contract);
    if (typeof contract.address != 'undefined') {
         console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
    }
 })

Then get the return contract address and in the same console do :

var MyContract = web3.eth.contract(freightContract.abi);
var param1 = "xx"
var parm2 = 2
MyContract.setFreight.call(param1,param2) or . sendTransaction(param1,param2,{from: web3.eth.accounts[0], gas:3000000}) 

in case you actually doing a transaction and not only reading data.

This should work.

Finally once your contract is deploy once you can access it again using :

var freightContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"contNumber","type":"string"},{"name":"s_Invoice","type":"string"},{"name":"c_Invoice","type":"string"},{"name":"s_number","type":"string"},{"name":"t_Weight","type":"uint256"},{"name":"t_Quantity","type":"uint256"}],"name":"setFreight","outputs":[],"type":"function"},{"constant":false,"inputs":[{"name":"contNumber","type":"string"},{"name":"s_Invoice","type":"string"},{"name":"c_Invoice","type":"string"},{"name":"s_number","type":"string"},{"name":"t_Weight","type":"uint256"},{"name":"t_Quantity","type":"uint256"}],"name":"getFreight","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"type":"function"},{"inputs":[],"type":"constructor"}]);

and Then

MyContract.at("your contract address");
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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