In the official Truffle Docs over here, it is demonstrated how to interact with a deployed contract. So far, I've come across only the Truffle Console, which is everything but intuitive for larger expressions and .then()-chains.

Is there a way to execute such a script from file, instead of using the interactive console?


The truffle console is also a nodejs console, so you can simply require any javascript file and execute it like you would in a regular node application.

If you're talking about how to access a deployed contract outside the console, then; after you've deployed the contract you'll get back an address which is where the contract lives. In your code you then import the deployed contract ABI, set the web3 provider, and tell truffle contract to use the deployed contract address.

It'll be something like this:

var tc = require('truffle-contract')

var abi = require('./contract-abi.json')
var MyContract = tc(abi)
var instance = await MyContract.at('0x123...abc')
var result = await instance.myMethod()

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.