0

just trying my first steps in ethereum and web3. So i found this tutorial: https://www.youtube.com/watch?v=hcTPjpPvas8

But it raise an error: index.html:85 Uncaught TypeError: TheContract.at is not a function at index.html:85

Here is my code:

var TheContract = new web3.eth.Contract([
    {
        "constant": false,
        "inputs": [
            {
                "name": "_fName",
                "type": "string"
            },
            {
                "name": "_age",
                "type": "uint256"
            }
        ],
        "name": "setInstructor",
        "outputs": [],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "function"
    },
    {
        "constant": true,
        "inputs": [],
        "name": "getInstructor",
        "outputs": [
            {
                "name": "",
                "type": "string"
            },
            {
                "name": "",
                "type": "uint256"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    }
    ]);
    
    //var AdressContract =  TheContract.at("0x5fd16b1Fac5835F744061ED2B92a83864aB75688");

    var theContractAt = TheContract.at('0x5fd16b1Fac5835F744061ED2B92a83864aB75688');
    console.log(theContractAt);

I guess, because the upper case in contract is also new to the new version of web3, that the .at() function changed... but I just cant find how they changed.

2
  • at is relevant on web3.js v0.x, or if you're using Truffle (which wraps web3.js functions regardless of web3.js version). You're probably on web3.js v1.x. Aug 20, 2020 at 16:05
  • 1
    Just change ]); to ], '0x5fd16b1Fac5835F744061ED2B92a83864aB75688');. Aug 20, 2020 at 16:07

1 Answer 1

2

Just change ]); to ], '0x5fd16b1Fac5835F744061ED2B92a83864aB75688');. – goodvibration

Works thanks

0

Your Answer

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

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