1

Let's suppose an existing Ethereum deployed contract.

I know the deployment Address and i have the contract's source code.

What i want to do is to call a function on this deployed contract from truffle console.

Is it possible and how can i do that ?

Thanks

1 Answer 1

0

Say you have a contract like the one below deployed at address 0x1f2deF1210B4D06B267A64b9888990734Aba7e24

pragma solidity ^0.8.1; contract test { string public initialString = "Hello World!"; function getString() public view returns (string memory) { return initialString; } } 

To create an instance of that contract:

truffle(develop)> contract = await test.at('0x1f2deF1210B4D06B267A64b9888990734Aba7e24') 

To call a function:

truffle(develop)> a = await contract.getString() 

To check the variable directly (if declared as public):

truffle(develop)> b = await.contract.initialString() 

This way, you will have in a and b the expected values.

Of course you need to point to the right Ethereum network within the truffle-config.js file in networks section.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.