3

The Javascript-API/geth wiki pages state that the at([address]) function does the following:

// initiate contract for an address
var myContractInstance = MyContract.at('0x78e97bcc5b5dd9ed228fed7a4887c0d7287344a9');

1. What does "instantiate by address" mean here?
2. What is going on when at is called?
3. Should the address parameter be from an already deployed contract, or a new address? _ 4. What should be returned?

When I've been using at(..) from a geth console attached to testrpc, it returns undefined. Should this be the case? For example following the example in this question with 'testrpc' set up like this:

testrpc -a 1000
geth attach rpc:http://localhost:8545

EDIT:

Note, I think I've found the source code:

/**
 * Should be called to get access to existing contract on a blockchain
 *
 * @method at
 * @param {Address} contract address (required)
 * @param {Function} callback {optional)
 * @returns {Contract} returns contract if no callback was passed,
 * otherwise calls callback function (err, contract)
 */
ContractFactory.prototype.at = function (address, callback) {
    var contract = new Contract(this.eth, this.abi, address);

    // this functions are not part of prototype,
    // because we dont want to spoil the interface
    addFunctionsToContract(contract);
    addEventsToContract(contract);

    if (callback) {
        callback(null, contract);
    }
    return contract;
};

/**
 * Should be called to create new contract instance
 *
 * @method Contract
 * @param {Array} abi
 * @param {Address} contract address
 */
var Contract = function (eth, abi, address) {
    this._eth = eth;
    this.transactionHash = null;
    this.address = address;
    this.abi = abi;
};

1 Answer 1

3

This function creates a new MyContract object with the address field set to the argument.

You should pass in the address of an already deployed contract.

The function returns an object that you can use to call ABI-specified functions of the contract.

There are no side effects, and the method does not check to ensure that there is actually at the contract you passed in. If not, you will get errors when you try to actually call the contract's methods.

1
  • 1
    And to clarify: the instiated MyContrcat object t is a proxy object to the deployed Ethereum smart contract. It uses the underlying web3 connection provider to connect with a running Ethereum node over JSON-RPC API to perform remote procedure calls. Commented Jan 6, 2017 at 18:52

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.