0

The documentation says:

Object - A contract object, which can be initiated as follows:

var MyContract = web3.eth.contract(abiArray);

// instantiate by address
var contractInstance = MyContract.at(address);

First, .contract doesn't exist but .Contract does.

So I try this:

var Keyserver = new web3.eth.Contract(abiArray);
var contract = Keyserver.at('0x6f4cf704c86da0afeb3cc28cda77f3c69d6e5e0d');

run, get error:

var contract = Keyserver.at('0x6f4cf704c86da0afeb3cc28cda77f3c69d6e5e0d'); ^

TypeError: Keyserver.at is not a function

console.log(Keyserver):

 'currentProvider',
  '_requestManager',
  'givenProvider',
  'providers',
  '_provider',
  'setProvider',
  'BatchRequest',
  'extend',
  'defaultAccount',
  'defaultBlock',
  'clearSubscriptions',
  'net',
  'accounts',
  'personal',
  'Contract',
  'Iban',
  'abi',
  'getProtocolVersion',
  'getCoinbase',
  'isMining',
  'getHashrate',
  'isSyncing',
  'getGasPrice',
  'getAccounts',
  'getBlockNumber',
  'getBalance',
  'getStorageAt',
  'getCode',
  'getBlock',
  'getUncle',
  'getBlockTransactionCount',
  'getBlockUncleCount',
  'getTransaction',
  'getTransactionFromBlock',
  'getTransactionReceipt',
  'getTransactionCount',
  'sendSignedTransaction',
  'signTransaction',
  'sendTransaction',
  'sign',
  'call',
  'estimateGas',
  'getCompilers',
  'compile',
  'submitWork',
  'getWork',
  'getPastLogs',
  'subscribe' ]
{ [Function: Contract]
  setProvider: [Function],
  defaultAccount: null,
  defaultBlock: 'latest',
  currentProvider: [Getter/Setter],
  _requestManager:
   RequestManager {
     provider: HttpProvider { host: 'http://localhost:8545', timeout: 0, connected: false },
     providers:
      { WebsocketProvider: [Function: WebsocketProvider],
        HttpProvider: [Function: HttpProvider],
        IpcProvider: [Function: IpcProvider] },
     subscriptions: {} },
  givenProvider: null,
  providers:
   { WebsocketProvider: [Function: WebsocketProvider],
     HttpProvider: [Function: HttpProvider],
     IpcProvider: [Function: IpcProvider] },
  _provider: HttpProvider { host: 'http://localhost:8545', timeout: 0, connected: false },
  BatchRequest: [Function: bound Batch],
  extend:
   { [Function: ex]
     formatters:
      { inputDefaultBlockNumberFormatter: [Function: inputDefaultBlockNumberFormatter],
        inputBlockNumberFormatter: [Function: inputBlockNumberFormatter],
        inputCallFormatter: [Function: inputCallFormatter],
        inputTransactionFormatter: [Function: inputTransactionFormatter],
        inputAddressFormatter: [Function: inputAddressFormatter],
        inputPostFormatter: [Function: inputPostFormatter],
        inputLogFormatter: [Function: inputLogFormatter],
        inputSignFormatter: [Function: inputSignFormatter],
        outputBigNumberFormatter: [Function: outputBigNumberFormatter],
        outputTransactionFormatter: [Function: outputTransactionFormatter],
        outputTransactionReceiptFormatter: [Function: outputTransactionReceiptFormatter],
        outputBlockFormatter: [Function: outputBlockFormatter],
        outputLogFormatter: [Function: outputLogFormatter],
        outputPostFormatter: [Function: outputPostFormatter],
        outputSyncingFormatter: [Function: outputSyncingFormatter] },
     utils:
      { _fireError: [Function: _fireError],
        _jsonInterfaceMethodToString: [Function: _jsonInterfaceMethodToString],
        randomHex: [Function: randomHex],
        _: [Object],
        BN: [Object],
        isBN: [Function: isBN],
        isBigNumber: [Function: isBigNumber],
        isHex: [Function: isHex],
        isHexStrict: [Function: isHexStrict],
        sha3: [Object],
        keccak256: [Object],
        soliditySha3: [Function: soliditySha3],
        isAddress: [Function: isAddress],
        checkAddressChecksum: [Function: checkAddressChecksum],
        toChecksumAddress: [Function: toChecksumAddress],
        toHex: [Function: toHex],
        toBN: [Function: toBN],
        bytesToHex: [Function: bytesToHex],
        hexToBytes: [Function: hexToBytes],
        hexToNumberString: [Function: hexToNumberString],
        hexToNumber: [Function: hexToNumber],
        toDecimal: [Function: hexToNumber],
        numberToHex: [Function: numberToHex],
        fromDecimal: [Function: numberToHex],
        hexToUtf8: [Function: hexToUtf8],
        hexToString: [Function: hexToUtf8],
        toUtf8: [Function: hexToUtf8],
        utf8ToHex: [Function: utf8ToHex],
        stringToHex: [Function: utf8ToHex],
        fromUtf8: [Function: utf8ToHex],
        hexToAscii: [Function: hexToAscii],
        toAscii: [Function: hexToAscii],
        asciiToHex: [Function: asciiToHex],
        fromAscii: [Function: asciiToHex],
        unitMap: [Object],
        toWei: [Function: toWei],
        fromWei: [Function: fromWei],
        padLeft: [Function: leftPad],
        leftPad: [Function: leftPad],
        padRight: [Function: rightPad],
        rightPad: [Function: rightPad],
        toTwosComplement: [Function: toTwosComplement] },
     Method: [Function: Method] },
  _ethAccounts:
   Accounts {
     currentProvider: [Getter/Setter],
     _requestManager: RequestManager { provider: [Object], providers: [Object], subscriptions: {} },
     givenProvider: null,
     providers:
      { WebsocketProvider: [Function: WebsocketProvider],
        HttpProvider: [Function: HttpProvider],
        IpcProvider: [Function: IpcProvider] },
     _provider: HttpProvider { host: 'http://localhost:8545', timeout: 0, connected: false },
     setProvider: [Function],
     _ethereumCall:
      { getId: [Object],
        getGasPrice: [Object],
        getTransactionCount: [Object] },
     wallet:
      Wallet {
        _accounts: [Circular],
        length: 0,
        defaultKeyName: 'web3js_wallet' } } }
/Users/quantum/scan/server.js:50
var contract = Keyserver.at('0x6f4cf704c86da0afeb3cc28cda77f3c69d6e5e0d');
                         ^

TypeError: Keyserver.at is not a function
    at Object.<anonymous> (/Users/quantum/scan/server.js:50:26)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)
    at Function.Module.runMain (module.js:676:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
~/scan/node server.js
[ 'currentProvider',
  '_requestManager',
  'givenProvider',
  'providers',
  '_provider',
  'setProvider',
  'BatchRequest',
  'extend',
  'defaultAccount',
  'defaultBlock',
  'clearSubscriptions',
  'net',
  'accounts',
  'personal',
  'Contract',
  'Iban',
  'abi',
  'getProtocolVersion',
  'getCoinbase',
  'isMining',
  'getHashrate',
  'isSyncing',
  'getGasPrice',
  'getAccounts',
  'getBlockNumber',
  'getBalance',
  'getStorageAt',
  'getCode',
  'getBlock',
  'getUncle',
  'getBlockTransactionCount',
  'getBlockUncleCount',
  'getTransaction',
  'getTransactionFromBlock',
  'getTransactionReceipt',
  'getTransactionCount',
  'sendSignedTransaction',
  'signTransaction',
  'sendTransaction',
  'sign',
  'call',
  'estimateGas',
  'getCompilers',
  'compile',
  'submitWork',
  'getWork',
  'getPastLogs',
  'subscribe' ]
{ [Function: Contract]
  setProvider: [Function],
  defaultAccount: null,
  defaultBlock: 'latest',
  currentProvider: [Getter/Setter],
  _requestManager:
   RequestManager {
     provider: HttpProvider { host: 'http://localhost:8545', timeout: 0, connected: false },
     providers:
      { WebsocketProvider: [Function: WebsocketProvider],
        HttpProvider: [Function: HttpProvider],
        IpcProvider: [Function: IpcProvider] },
     subscriptions: {} },
  givenProvider: null,
  providers:
   { WebsocketProvider: [Function: WebsocketProvider],
     HttpProvider: [Function: HttpProvider],
     IpcProvider: [Function: IpcProvider] },
  _provider: HttpProvider { host: 'http://localhost:8545', timeout: 0, connected: false },
  BatchRequest: [Function: bound Batch],
  extend:
   { [Function: ex]
     formatters:
      { inputDefaultBlockNumberFormatter: [Function: inputDefaultBlockNumberFormatter],
        inputBlockNumberFormatter: [Function: inputBlockNumberFormatter],
        inputCallFormatter: [Function: inputCallFormatter],
        inputTransactionFormatter: [Function: inputTransactionFormatter],
        inputAddressFormatter: [Function: inputAddressFormatter],
        inputPostFormatter: [Function: inputPostFormatter],
        inputLogFormatter: [Function: inputLogFormatter],
        inputSignFormatter: [Function: inputSignFormatter],
        outputBigNumberFormatter: [Function: outputBigNumberFormatter],
        outputTransactionFormatter: [Function: outputTransactionFormatter],
        outputTransactionReceiptFormatter: [Function: outputTransactionReceiptFormatter],
        outputBlockFormatter: [Function: outputBlockFormatter],
        outputLogFormatter: [Function: outputLogFormatter],
        outputPostFormatter: [Function: outputPostFormatter],
        outputSyncingFormatter: [Function: outputSyncingFormatter] },
     utils:
      { _fireError: [Function: _fireError],
        _jsonInterfaceMethodToString: [Function: _jsonInterfaceMethodToString],
        randomHex: [Function: randomHex],
        _: [Object],
        BN: [Object],
        isBN: [Function: isBN],
        isBigNumber: [Function: isBigNumber],
        isHex: [Function: isHex],
        isHexStrict: [Function: isHexStrict],
        sha3: [Object],
        keccak256: [Object],
        soliditySha3: [Function: soliditySha3],
        isAddress: [Function: isAddress],
        checkAddressChecksum: [Function: checkAddressChecksum],
        toChecksumAddress: [Function: toChecksumAddress],
        toHex: [Function: toHex],
        toBN: [Function: toBN],
        bytesToHex: [Function: bytesToHex],
        hexToBytes: [Function: hexToBytes],
        hexToNumberString: [Function: hexToNumberString],
        hexToNumber: [Function: hexToNumber],
        toDecimal: [Function: hexToNumber],
        numberToHex: [Function: numberToHex],
        fromDecimal: [Function: numberToHex],
        hexToUtf8: [Function: hexToUtf8],
        hexToString: [Function: hexToUtf8],
        toUtf8: [Function: hexToUtf8],
        utf8ToHex: [Function: utf8ToHex],
        stringToHex: [Function: utf8ToHex],
        fromUtf8: [Function: utf8ToHex],
        hexToAscii: [Function: hexToAscii],
        toAscii: [Function: hexToAscii],
        asciiToHex: [Function: asciiToHex],
        fromAscii: [Function: asciiToHex],
        unitMap: [Object],
        toWei: [Function: toWei],
        fromWei: [Function: fromWei],
        padLeft: [Function: leftPad],
        leftPad: [Function: leftPad],
        padRight: [Function: rightPad],
        rightPad: [Function: rightPad],
        toTwosComplement: [Function: toTwosComplement] },
     Method: [Function: Method] },
  _ethAccounts:
   Accounts {
     currentProvider: [Getter/Setter],
     _requestManager: RequestManager { provider: [Object], providers: [Object], subscriptions: {} },
     givenProvider: null,
     providers:
      { WebsocketProvider: [Function: WebsocketProvider],
        HttpProvider: [Function: HttpProvider],
        IpcProvider: [Function: IpcProvider] },
     _provider: HttpProvider { host: 'http://localhost:8545', timeout: 0, connected: false },
     setProvider: [Function],
     _ethereumCall:
      { getId: [Object],
        getGasPrice: [Object],
        getTransactionCount: [Object] },
     wallet:
      Wallet {
        _accounts: [Circular],
        length: 0,
        defaultKeyName: 'web3js_wallet' } } }
Contract {
  currentProvider: [Getter/Setter],
  _requestManager:
   RequestManager {
     provider: HttpProvider { host: 'http://localhost:8545', timeout: 0, connected: false },
     providers:
      { WebsocketProvider: [Function: WebsocketProvider],
        HttpProvider: [Function: HttpProvider],
        IpcProvider: [Function: IpcProvider] },
     subscriptions: {} },
  givenProvider: null,
  providers:
   { WebsocketProvider: [Function: WebsocketProvider],
     HttpProvider: [Function: HttpProvider],
     IpcProvider: [Function: IpcProvider] },
  _provider: HttpProvider { host: 'http://localhost:8545', timeout: 0, connected: false },
  setProvider: [Function],
  BatchRequest: [Function: bound Batch],
  extend:
   { [Function: ex]
     formatters:
      { inputDefaultBlockNumberFormatter: [Function: inputDefaultBlockNumberFormatter],
        inputBlockNumberFormatter: [Function: inputBlockNumberFormatter],
        inputCallFormatter: [Function: inputCallFormatter],
        inputTransactionFormatter: [Function: inputTransactionFormatter],
        inputAddressFormatter: [Function: inputAddressFormatter],
        inputPostFormatter: [Function: inputPostFormatter],
        inputLogFormatter: [Function: inputLogFormatter],
        inputSignFormatter: [Function: inputSignFormatter],
        outputBigNumberFormatter: [Function: outputBigNumberFormatter],
        outputTransactionFormatter: [Function: outputTransactionFormatter],
        outputTransactionReceiptFormatter: [Function: outputTransactionReceiptFormatter],
        outputBlockFormatter: [Function: outputBlockFormatter],
        outputLogFormatter: [Function: outputLogFormatter],
        outputPostFormatter: [Function: outputPostFormatter],
        outputSyncingFormatter: [Function: outputSyncingFormatter] },
     utils:
      { _fireError: [Function: _fireError],
        _jsonInterfaceMethodToString: [Function: _jsonInterfaceMethodToString],
        randomHex: [Function: randomHex],
        _: [Object],
        BN: [Object],
        isBN: [Function: isBN],
        isBigNumber: [Function: isBigNumber],
        isHex: [Function: isHex],
        isHexStrict: [Function: isHexStrict],
        sha3: [Object],
        keccak256: [Object],
        soliditySha3: [Function: soliditySha3],
        isAddress: [Function: isAddress],
        checkAddressChecksum: [Function: checkAddressChecksum],
        toChecksumAddress: [Function: toChecksumAddress],
        toHex: [Function: toHex],
        toBN: [Function: toBN],
        bytesToHex: [Function: bytesToHex],
        hexToBytes: [Function: hexToBytes],
        hexToNumberString: [Function: hexToNumberString],
        hexToNumber: [Function: hexToNumber],
        toDecimal: [Function: hexToNumber],
        numberToHex: [Function: numberToHex],
        fromDecimal: [Function: numberToHex],
        hexToUtf8: [Function: hexToUtf8],
        hexToString: [Function: hexToUtf8],
        toUtf8: [Function: hexToUtf8],
        utf8ToHex: [Function: utf8ToHex],
        stringToHex: [Function: utf8ToHex],
        fromUtf8: [Function: utf8ToHex],
        hexToAscii: [Function: hexToAscii],
        toAscii: [Function: hexToAscii],
        asciiToHex: [Function: asciiToHex],
        fromAscii: [Function: asciiToHex],
        unitMap: [Object],
        toWei: [Function: toWei],
        fromWei: [Function: fromWei],
        padLeft: [Function: leftPad],
        leftPad: [Function: leftPad],
        padRight: [Function: rightPad],
        rightPad: [Function: rightPad],
        toTwosComplement: [Function: toTwosComplement] },
     Method: [Function: Method] },
  clearSubscriptions: [Function],
  options: { address: [Getter/Setter], jsonInterface: [Getter/Setter] },
  defaultAccount: [Getter/Setter],
  defaultBlock: [Getter/Setter],
  methods:
   { owners: [Function: bound _createTxObject],
     '0x025e7c27': [Function: bound _createTxObject],
     'owners(uint256)': [Function: bound _createTxObject],
     ownersNum: [Function: bound _createTxObject],
     '0x195fa903': [Function: bound _createTxObject],
     'ownersNum()': [Function: bound _createTxObject],
     buyKey: [Function: bound _createTxObject],
     '0xe95db6f9': [Function: bound _createTxObject],
     'buyKey()': [Function: bound _createTxObject] },
  events: { allEvents: [Function: bound ] },
  _address: null,
  _jsonInterface:
   [ { constant: true,
       inputs: [Array],
       name: 'owners',
       outputs: [Array],
       payable: false,
       stateMutability: 'view',
       type: 'function',
       signature: '0x025e7c27' },
     { constant: true,
       inputs: [],
       name: 'ownersNum',
       outputs: [Array],
       payable: false,
       stateMutability: 'view',
       type: 'function',
       signature: '0x195fa903' },
     { constant: false,
       inputs: [],
       name: 'buyKey',
       outputs: [],
       payable: true,
       stateMutability: 'payable',
       type: 'function',
       signature: '0xe95db6f9' } ] }
~/scan/
1

Documentation you are quoting is for Elementrem web3.js, but you are actually using Ethereum web3.js. That's why documentation does not fit. You need to follow this documentation.

| improve this answer | |
0
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
let c = new web3.eth.Contract(abi, '0x6f4cf704c86da0afeb3cc28cda77f3c69d6e5e0d');
| improve this answer | |
0

Use web3js-raw node package to easily deploy your contract

| improve this answer | |
  • This question is about reading an already deployed contract and referencing it with web3 – quantumpotato Jan 12 '18 at 17:08

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.