1

I am using web3@0.20.7 and infura to connect Ropsten testing network. I haven't opened my website(using ethereum) for a while. Today I restarted my website, and I can not connect to ethereum with Infura. Here's code

var express = require('express');
var router = express.Router();
var Web3 = require('web3');
const testnet = 'https://ropsten.infura.io/';
const web3 = new Web3(new Web3.providers.HttpProvider(testnet));
var contractAddress = '0x72682d0d54c7ED7cdDdAa66E6DD7171f2B9c626C';
var contractABI =[{"constant":false,"inputs":[{"name":"CopyMatch","type..........
var contract = web3.eth.contract(contractABI).at(contractAddress);

Variable "contract" cannot get anything. How can I revise it? Thanks.

  • 1
    At least your web3 version is ancient. I suggest you update. – Lauri Peltonen Mar 9 '20 at 16:33
  • Please elaborate on I can not connect to ethereum with Infura, and please explain what does Variable "contract" cannot get anything even mean. – goodvibration Mar 9 '20 at 18:58
  • Please check what is there in your contract, console.log it. I think it is not able to create an instance for you contract. – vteja711 Mar 10 '20 at 10:31
  • And also please upgrade your web3 and use the new method web3.eth.Contract(<<contract_abi>>, <<contract_address>>); – vteja711 Mar 10 '20 at 10:32
  • Also I think you might just have a promise in your contract. So use await and check – vteja711 Mar 10 '20 at 10:35
1

I am able to connect to your contract. Try this. I got your abi from etherscan.

const express = require('express')
const Web3 = require('web3')
const web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/'));
const abi = [{"constant":false,"inputs":[{"name":"CopyMatch","type":"address"}],"name":"proxy_ActiveStrategy","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_signature","type":"bytes"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"},{"name":"_fee","type":"uint256"},{"name":"_nonce","type":"uint256"}],"name":"transferPreSigned","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"hash","type":"bytes32"},{"name":"sig","type":"bytes"}],"name":"recover","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":false,"inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"getNonce","outputs":[{"name":"nonce","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"CopyMatch","type":"address"}],"name":"proxy_inActiveStrategy","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_signature","type":"bytes"},{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"},{"name":"_fee","type":"uint256"},{"name":"_nonce","type":"uint256"}],"name":"approvePreSigned","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_subtractedValue","type":"uint256"}],"name":"decreaseApproval","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"Initial_Supply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"CopyMatch","type":"address"},{"name":"addrCopyTrader","type":"address"},{"name":"id","type":"uint256"},{"name":"endAmount","type":"uint256"}],"name":"proxy_endCommit","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_signature","type":"bytes"},{"name":"_spender","type":"address"},{"name":"_subtractedValue","type":"uint256"},{"name":"_fee","type":"uint256"},{"name":"_nonce","type":"uint256"}],"name":"decreaseApprovalPreSigned","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_signature","type":"bytes"},{"name":"_spender","type":"address"},{"name":"_addedValue","type":"uint256"},{"name":"_fee","type":"uint256"},{"name":"_nonce","type":"uint256"}],"name":"increaseApprovalPreSigned","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_signature","type":"bytes"},{"name":"_to","type":"address"},{"name":"_controlId","type":"uint256"},{"name":"_fee","type":"uint256"},{"name":"_nonce","type":"uint256"},{"name":"CopyMatch","type":"address"},{"name":"addrCopyTrader","type":"address"},{"name":"id","type":"uint256"},{"name":"amount","type":"uint256"},{"name":"otherData","type":"string"},{"name":"endAmount","type":"uint256"}],"name":"controlPreSigned","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"CopyMatch","type":"address"},{"name":"addrCopyTrader","type":"address"},{"name":"id","type":"uint256"},{"name":"amount","type":"uint256"},{"name":"otherData","type":"string"}],"name":"proxy_createCommit","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_spender","type":"address"},{"name":"_addedValue","type":"uint256"}],"name":"increaseApproval","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"_token","type":"address"},{"name":"_functionSig","type":"bytes4"},{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"},{"name":"_fee","type":"uint256"},{"name":"_nonce","type":"uint256"}],"name":"recoverPreSignedHash","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"pure","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"ControlPreSigned_Transfer_Fee","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":true,"name":"delegate","type":"address"},{"indexed":false,"name":"_controlId","type":"uint256"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"fee","type":"uint256"}],"name":"ControlPreSigned","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"TransferPreSigned_Transfer_Fee","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":true,"name":"delegate","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"fee","type":"uint256"}],"name":"TransferPreSigned","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":true,"name":"delegate","type":"address"},{"indexed":false,"name":"amount","type":"uint256"},{"indexed":false,"name":"fee","type":"uint256"}],"name":"ApprovalPreSigned","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"existingOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"transferOwner","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}];
const app = express();
var contractAddress = '0x72682d0d54c7ED7cdDdAa66E6DD7171f2B9c626C';
const name = '';

    //Call the blockchain to send the details
    const nid = async() => {
        var contract = new web3.eth.Contract(abi,contractAddress);
        console.log("contract methods:", contract.methods);
    }
    nid();

I am able to log your methods.

contract methods: {
  proxy_ActiveStrategy: [Function: bound _createTxObject],
  '0x06a60e70': [Function: bound _createTxObject],
  'proxy_ActiveStrategy(address)': [Function: bound _createTxObject],
  name: [Function: bound _createTxObject],
  '0x06fdde03': [Function: bound _createTxObject],
  'name()': [Function: bound _createTxObject],
  approve: [Function: bound _createTxObject],
  '0x095ea7b3': [Function: bound _createTxObject],
  'approve(address,uint256)': [Function: bound _createTxObject],
  transferPreSigned: [Function: bound _createTxObject],
  '0x1296830d': [Function: bound _createTxObject],
  'transferPreSigned(bytes,address,uint256,uint256,uint256)': [Function: bound _createTxObject],
  totalSupply: [Function: bound _createTxObject],
  '0x18160ddd': [Function: bound _createTxObject],
  'totalSupply()': [Function: bound _createTxObject],
  recover: [Function: bound _createTxObject],
  '0x19045a25': [Function: bound _createTxObject],
  'recover(bytes32,bytes)': [Function: bound _createTxObject],
  transferFrom: [Function: bound _createTxObject],
  '0x23b872dd': [Function: bound _createTxObject],
  'transferFrom(address,address,uint256)': [Function: bound _createTxObject],
  getNonce: [Function: bound _createTxObject],
  '0x2d0335ab': [Function: bound _createTxObject],
  'getNonce(address)': [Function: bound _createTxObject],
  decimals: [Function: bound _createTxObject],
  '0x313ce567': [Function: bound _createTxObject],
  'decimals()': [Function: bound _createTxObject],
  kill: [Function: bound _createTxObject],
  '0x41c0e1b5': [Function: bound _createTxObject],
  'kill()': [Function: bound _createTxObject],
  proxy_inActiveStrategy: [Function: bound _createTxObject],
  '0x42c1eb38': [Function: bound _createTxObject],
  'proxy_inActiveStrategy(address)': [Function: bound _createTxObject],
  approvePreSigned: [Function: bound _createTxObject],
  '0x617b390b': [Function: bound _createTxObject],
  'approvePreSigned(bytes,address,uint256,uint256,uint256)': [Function: bound _createTxObject],
  decreaseApproval: [Function: bound _createTxObject],
  '0x66188463': [Function: bound _createTxObject],
  'decreaseApproval(address,uint256)': [Function: bound _createTxObject],
  balanceOf: [Function: bound _createTxObject],
  '0x70a08231': [Function: bound _createTxObject],
  'balanceOf(address)': [Function: bound _createTxObject],
  Initial_Supply: [Function: bound _createTxObject],
  '0x7bc14a67': [Function: bound _createTxObject],
  'Initial_Supply()': [Function: bound _createTxObject],
  proxy_endCommit: [Function: bound _createTxObject],
  '0x7f3e4852': [Function: bound _createTxObject],
  'proxy_endCommit(address,address,uint256,uint256)': [Function: bound _createTxObject],
  decreaseApprovalPreSigned: [Function: bound _createTxObject],
  '0x8be52783': [Function: bound _createTxObject],
  'decreaseApprovalPreSigned(bytes,address,uint256,uint256,uint256)': [Function: bound _createTxObject],
  owner: [Function: bound _createTxObject],
  '0x8da5cb5b': [Function: bound _createTxObject],
  'owner()': [Function: bound _createTxObject],
  symbol: [Function: bound _createTxObject],
  '0x95d89b41': [Function: bound _createTxObject],
  'symbol()': [Function: bound _createTxObject],
  transfer: [Function: bound _createTxObject],
  '0xa9059cbb': [Function: bound _createTxObject],
  'transfer(address,uint256)': [Function: bound _createTxObject],
  increaseApprovalPreSigned: [Function: bound _createTxObject],
  '0xadb8249e': [Function: bound _createTxObject],
  'increaseApprovalPreSigned(bytes,address,uint256,uint256,uint256)': [Function: bound _createTxObject],
  controlPreSigned: [Function: bound _createTxObject],
  '0xbe997005': [Function: bound _createTxObject],
  'controlPreSigned(bytes,address,uint256,uint256,uint256,address,address,uint256,uint256,string,uint256)': [Function: bound _createTxObject],
  proxy_createCommit: [Function: bound _createTxObject],
  '0xd5b71241': [Function: bound _createTxObject],
  'proxy_createCommit(address,address,uint256,uint256,string)': [Function: bound _createTxObject],
  increaseApproval: [Function: bound _createTxObject],
  '0xd73dd623': [Function: bound _createTxObject],
  'increaseApproval(address,uint256)': [Function: bound _createTxObject],
  allowance: [Function: bound _createTxObject],
  '0xdd62ed3e': [Function: bound _createTxObject],
  'allowance(address,address)': [Function: bound _createTxObject],
  recoverPreSignedHash: [Function: bound _createTxObject],
  '0xe9024691': [Function: bound _createTxObject],
  'recoverPreSignedHash(address,bytes4,address,uint256,uint256,uint256)': [Function: bound _createTxObject],
  transferOwnership: [Function: bound _createTxObject],
  '0xf2fde38b': [Function: bound _createTxObject],
  'transferOwnership(address)': [Function: bound _createTxObject]
}

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.