I want to access the data which i sent via a function during the previous contract instance . Is it possible to retrieve the data by the the contract instance or transaction hash ?
You do not need to redeploy a contract, if it is already deployed you need to create an instance that point to the contract address
async function queryContract() {
const ContractABI = [...]; // <-- Contract ABI
const ContractAddress = "0x1234...."; // <-- Deployed contract address
// Assign deployed address of a contract
const myContract = new web3.eth.Contract(ContractABI, ContractAddress);
// Send a transaction
await myContract.methods.sendHash("0x12341234")
.send({
from: MyAccount,
gas: 2000000,
gasPrice: '30000000000'
});
// Query modified data
const hash = await myContract.methods.getHash().call();
console.log(hash)
}
queryContract();
-
Thank you so much,if i want to get the hash which was sent previously via function to the contract .How do i access it, Is it possible to get via transaction sent? – Santosh Kaluva May 16 '18 at 4:51
-
To access data in a deplyed contract you need the contract address and the contract ABI. Then you can call any method exposed y the interface. Follow the examples on how to use it from web3 documentation web3js.readthedocs.io/en/1.0/web3-eth-contract.html – Ismael May 16 '18 at 18:15