[Ethereum] Truffle develop get new contract instance from contract address

contract-invocationprivate-blockchainsoliditytruffleweb3js

From a truffle develop console, is there a way I can get the contract instance from the contract's address?

I have a remote ec2 with truffle/geth installed and truffle develop instance running. From a local truffle develop console, I have deployed my contracts to that remote network (using the truffle migrate --compile-all --reset --network remote_network_name). The contracts deployed successfully, and I have an address for where the contract is stored.

In a truffle develop console on the remote server, I have tried Contract_Name.deployed().then(function(instance) {app = instance; }) to get the instance, but I get a Contract_Name is undefined error.

From a truffle develop console on the remote server, is there a way I can get the contract instance from the contract's address?

Maybe something like MyContract = new Contract.at("ContractAddress")?

Best Answer

There is a much easier way when using truffle.

First include the contract artifact, same as when creating a new contract in truffle.

let MyContract = artifacts.require("./MyContract.sol");

then in script:

let myContract = await MyContract.at('my contract address');

This way no need to take the ABI from another file etc.

Related Topic