TypeError: LoginContract.LoginAttempt no es una función

Aquí está mi Login.sol

pragma solidity ^0.4.2;

contract Login {
   event LoginAttempt(address sender, string challenge);

   function Login (string challenge) public {
       LoginAttempt(msg.sender, challenge);
   }

}

Aquí está mi servidor.js

const LoginContract = new web3.eth.Contract(abiLogin);

// LoginAttempt is the name of the event that signals logins in the
// Login contract. This is specified in the login.sol file.

loginAttempt = LoginContract.LoginAttempt({});

challenges = {};
successfulLogins = {};

loginAttempt.watch({}, '', function(error, event) {
    if(error) {
        console.log(error);
        return;
    }

    console.log(event);

    const sender = event.args.sender.toLowerCase();

    // If the challenge sent through Ethereum matches the one we generated,
    // mark the login attempt as valid, otherwise ignore it.
    if(challenges[sender] === event.args.challenge) {
        successfulLogins[sender] = true;
    }
});

No sé qué está mal con mi código, seguí las instrucciones de https://auth0.com/blog/an-introduction-to-ethereum-and-smart-contracts-part-2/

Pero por alguna razón, el evento de mi contrato no se puede ver. ¿Alguien puede ayudarme a resolver este problema?

EDITAR 1 Como necesito implementar el contrato, cambié mi código anterior a estas cosas a continuación

let LoginContract = new web3.eth.Contract(abiLogin);

web3.eth.personal.unlockAccount('6ded1c5b448819a6cde4293e33fbe54583ef5c52', 'bank')
.then(result => {
    util.log(`>>>>> contractApi - Is bank account unlocked ? ${result}`);
    util.log('>>>>> contractApi - Ready to deploy Login contract');

    LoginContract.deploy({
        data: '0x'+binLogin,
        arguments: ['']
    })
    .send({
        from: '6ded1c5b448819a6cde4293e33fbe54583ef5c52',
        gas: gas
    })
    .on('receipt', receipt => {
        util.log(`>>>>> contractApi - Login Contract sucessfully deployed @ address: ${receipt.contractAddress}`);
        // LoginAttempt is the name of the event that signals logins in the
        // Login contract. This is specified in the login.sol file.

        const loginContract = LoginContract.at(`${receipt.contractAddress}`)

        loginAttempt = loginContract.LoginAttempt();

        challenges = {};
        successfulLogins = {};

        loginAttempt.watch((error, event) => {
            if(error) {
                console.log(error);
                return;
            }

            console.log(event);

            const sender = event.args.sender.toLowerCase();

            // If the challenge sent through Ethereum matches the one we generated,
            // mark the login attempt as valid, otherwise ignore it.
            if(challenges[sender] === event.args.challenge) {
                successfulLogins[sender] = true;
            }
        });

        secret = process.env.JWT_SECRET || "my super secret passcode";

        util.log('>>>>> setup - Completed !!!')
    });
}, error => {
    util.log(`***** contractApi - Bank account unlock error - ${error}`);
});

Pero ocurre un nuevo error, TypeError: LoginContract.at is not a function . ¿Qué debo hacer en este caso? ¿Este problema está relacionado con la instalación del módulo web3?

Respuestas (1)

Te perdiste una línea que también se explica en el tutorial, y la más importante:

const loginContract = LoginContract.at(process.env.LOGIN_CONTRACT_ADDRESS ||
                      '0xf7b06365e9012592c8c136b71c7a2475c7a94d71');

que en esta línea en realidad apunta a la instancia del contrato en esa dirección específica. Puede obtener la dirección del contrato (0xf7...) cuando implemente su contrato (la trufa podría ser útil).

Hm ya veo, no estoy usando trufa. Lo que hice fue implementar el contrato manualmente, pero el problema persiste, TypeError: LoginContract.at no es una función.
¿Qué versión de web3 estás usando?
¿Cómo se comprueba la versión web3?
Mi versión web3 es "web3@0.18.4"
entonces no necesita newinstanciar el contrato:. solo let LoginContract = new web3.eth.Contract(abiLogin);y luego const contractInstance = LoginContract.at(address). github.com/ethereum/wiki/wiki/JavaScript-API#web3ethcontract
Gracias por la respuesta, me di cuenta de lo diferentes que son las versiones web3.
sí, lo siento, en realidad olvidé eliminar lo nuevo de mi comentario. problema de copiar y pegar.