+
Skip to content

Add useWeb3Contract hooks in README #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ function App() {
- [`useNFTBalances()`](#usenftbalances)
- [`useNFTTransfers()`](#usenfttransfers)
- [`useTokenPrice()`](#usetokenprice)
- [`useWeb3Contract()`](#useweb3contract)
- [Dex Plugin Hooks](#dex-plugin-hooks)
- [`useOneInchQuote()`](#useoneinchquote)
- [`useOneInchSwap()`](#useoneinchswap)
Expand Down Expand Up @@ -1403,6 +1404,74 @@ const TokenPrice = () => {
}

```

### `useWeb3Contract()`

You can use the `useWeb3Contract` hook to execute on-chain functions. You need to provide the correct `abi` of the contract, the corresponding `contractAddress`, the `functionName` that you would like to execute, and any parameters (`params`) thet you need to send with the function.

**Options**:
- `address` : The contract address (i.e. 0x1a2b3x...).
- `functionName` : The name of the contract's function that you want to call.
- `abi` : The contract's abi.
- `params` (optional): Any parameter you want to send with the function.

*Example:*

```jsx
const ShowUniswapObserveValues = () => {
const { data, error, runContractFunction, isFetching, isLoading } =
useWeb3Contract({
abi: usdcEthPoolAbi,
contractAddress: usdcEthPoolAddress,
functionName: "observe",
params: {
secondsAgos: [0, 10],
},
});

return (
<div>
{error && <ErrorMessage error={error} />}
<button onClick={() => runContractFunction()} disabled={isFetching}>
Fetch data
</button>
{data && <pre>{JSON.stringify(data)}</pre>}
</div>
);
};
```

*Example with executing by fetch:*

```jsx
const ShowUniswapObserveValues = () => {
const { data, error, runContractFunction, isFetching, isLoading } =
useWeb3Contract();

const options = {
abi: usdcEthPoolAbi,
contractAddress: usdcEthPoolAddress,
functionName: "observe",
params: {
secondsAgos: [0, 10],
},
};

return (
<div>
{error && <ErrorMessage error={error} />}
<button
onClick={() => runContractFunction({ params: options })}
disabled={isFetching}
>
Fetch data
</button>
{data && <pre>{JSON.stringify(data)}</pre>}
</div>
);
};
```

## Dex Plugin Hooks

### `useOneInchQuote()`
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载