i want to use the "set" function ,but the console tells me that i can 't ,and i want to know how can i use the abi .......
here are my code !
`import React, { Component } from "react";
import SimpleStorageContract from "./contracts/SimpleStorage.json";
import getWeb3 from "./getWeb3";
import "./App.css";
var instance;
class App extends Component {
state = { storageValue: 0, web3: null, accounts: null, contract: null };
componentDidMount = async () => {
try {
const web3 = await getWeb3();
// Use web3 to get the user's accounts.
const accounts = await web3.eth.getAccounts();
// Get the contract instance.
const networkId = await web3.eth.net.getId();
// Get network provider and web3 instance.
const deployedNetwork = SimpleStorageContract.networks[networkId];
instance = new web3.eth.Contract(SimpleStorageContract.abi
,deployedNetwork && deployedNetwork.address,);
// Set web3, accounts, and contract to the state, and then proceed with an
// example of interacting with the contract's methods.
this.setState({ web3, accounts, contract: instance }, this.runExample);
} catch (error) {
// Catch any errors for any of the above operations.
alert(
`Failed to load web3, accounts, or contract. Check console for details.`,
);
console.error(error);
}
// Stores a given value, 5 by default.
await contract.methods.set(1000).send({ from: accounts[0] });
// Get the value from the contract to prove it worked.
const response = await contract.methods.get().call();
// Update state with the result.
this.setState({ storageValue: response });
};
render() {
if (!this.state.web3) {
return
Loading Web3, accounts, and contract...
;
}
return (
Good to Go!
Your Truffle Box is installed and ready.
Smart Contract Example
If your contracts compiled and migrated successfully, below will show
a stored value of 1000 (by default).
Try changing the value stored on line 40 of App.js.
i want to use the "set" function ,but the console tells me that i can 't ,and i want to know how can i use the abi ....... here are my code !
`import React, { Component } from "react"; import SimpleStorageContract from "./contracts/SimpleStorage.json"; import getWeb3 from "./getWeb3"; import "./App.css";
var instance;
class App extends Component { state = { storageValue: 0, web3: null, accounts: null, contract: null };
componentDidMount = async () => { try { const web3 = await getWeb3(); // Use web3 to get the user's accounts. const accounts = await web3.eth.getAccounts(); // Get the contract instance. const networkId = await web3.eth.net.getId(); // Get network provider and web3 instance. const deployedNetwork = SimpleStorageContract.networks[networkId];
}; runExample = async () => { const { accounts, contract } = this.state;
};
render() { if (!this.state.web3) { return
Good to Go!
Your Truffle Box is installed and ready.
Smart Contract Example
If your contracts compiled and migrated successfully, below will show a stored value of 1000 (by default).
Try changing the value stored on line 40 of App.js.
} }
export default App; `