# CallGenericWriteFunction

{% hint style="info" %}
This function triggers a modal for the user to confirm the transaction
{% endhint %}

{% hint style="danger" %}
This is an advanced feature and <mark style="color:red;">can drain user wallet funds</mark> if you interact with a malicious contract. Only link to trusted smart contract authors.
{% endhint %}

## Description

This allows you to call any smart contract function and process the response. This function should be used to query functions that require the users signature, hence it should be invoked only once the user is logged in.

## Details

### Signature

`CallGenericWriteFunction(args)`

### Arguments

<table><thead><tr><th width="258">Parameter</th><th width="114">Type</th><th>Definition</th></tr></thead><tbody><tr><td><code>args.callback?</code></td><td>Function</td><td><p>Function to callback upon getting result from the smart contract function call<br><br>For numerical return values, please refer to the <a href="#handling-numerical-values">section below</a>.<br><br>Structure of result object passed into callback function:</p><pre class="language-json" data-line-numbers><code class="lang-json"><strong>{
</strong><strong>    "status": 1/0, // success or fail
</strong><strong>    "error": "", // error string if any
</strong><strong>    "data": {any}, // data returned from the smart contract function call
</strong><strong>}
</strong></code></pre></td></tr><tr><td><code>args.contractAddress</code></td><td>String</td><td>Contract address of the smart contract to be called</td></tr><tr><td><code>args.functionABI</code></td><td>JSON</td><td>The JSON object for the <a href="https://ethereum.org/en/developers/docs/smart-contracts/compiling/#web-applications">smart contract ABI</a></td></tr><tr><td><code>args.functionName</code></td><td>String</td><td>Name of the function to be called</td></tr><tr><td><code>args.value?</code></td><td>Number</td><td>The value to be sent along with the smart contract invocation. Please refer to the <a href="#handling-numerical-values">section below</a> for more information.</td></tr><tr><td><code>args.chain</code></td><td>chain (class)</td><td>Which chain to broadcast the transaction on. Pick a chain from the <a href="../../constants/chain#supported-chains">supported chains list</a></td></tr><tr><td><code>args.params</code></td><td>array</td><td>Array of objects that will be sent as the arguments to the smart contract function. Please ensure that the order of params matches the contract ABI.<br><br>For large numerical inputs, please refer to the <a href="#handling-numerical-values">section below</a>.</td></tr></tbody></table>

### Return Value

None

### Handling Large Numerical Values

{% hint style="warning" %}
Applicable to EVM Chains only
{% endhint %}

While passing in large numerical values (values above **9007199254740991**) in `args.params`, a conversion to BigNumber format needs to be made. You can use the following methods that convert the number to and from the appropriate format:

`ConvertNumberToBigNumber(number, decimal)` - Use this method while passing in numbers as params to a smart function that requires uint256 numbers

`ConvertBigNumberToNumber(bigNumber, decimal)` - Use this method while converting response values from a smart contract function call (which are in bigNumber format) to a JS Number

## Example

{% code lineNumbers="true" %}

```jsx
import { useMetafi, chains } from '@metafi/react-sdk';
import stakeContractAbi from '../contracts/abi/stakeContract.json'

function StakeUSDC(user_uuid) {
    const { CallGenericWriteFunction } = useMetafi();

    stakeContractAddress = "0xF5C9F957705bea56a7e806943f98F7877B995826"
    const callback = (res) => {
        console.log(res)
    }
    
    const stake = () => {
        CallGenericWriteFunction({
            callback: callback,
            chain: chains.eth,             
            contractAddress: stakeContractAddress,   
            functionABI: stakeContractAbi.abi,   
            functionName: "stake",
            value: 1,
            params: [],               
        });
    }
    
    return (
        <>
           <button onClick={stake}>Stake ETH</button>
        </>
    );
};
```

{% endcode %}
