Skip to content

Added the Feature of contract Interactions (Read/Write Operations)

Choose a tag to compare

@Nworah-Gabriel Nworah-Gabriel released this 22 Apr 14:41
· 9 commits to main since this release

Release Notes - Version 1.0.2

Added

  • Contract Interaction: We've added new functionalities to the library for interacting with smart contracts. You can now easily perform both read and write operations on contracts.

Features:

  • Read Operations:

    • Fetch data from smart contracts using the provided methods (e.g., getBalance, getOwner, etc.).
    • Supports querying contract state variables and getting information like balances, ownership, and more.
  • Write Operations:

    • Submit transactions to smart contracts for modifying their state (e.g., transfer, mint, burn, etc.).
    • Automatically handles gas estimation and transaction sending.

Improvements:

  • Enhanced error handling for transaction failure scenarios.
  • Optimized performance for interacting with Ethereum-based networks.

Breaking Changes:

  • None in this release.

Example Usage:

// contract ABI
            const Abi = [
            {
                "inputs": [
                    {
                        "internalType": "int256",
                        "name": "_value",
                        "type": "int256"
                    }
                ],
                "name": "setValue",
                "outputs": [],
                "stateMutability": "nonpayable",
                "type": "function"
            },
            {
                "inputs": [],
                "name": "get",
                "outputs": [
                    {
                        "internalType": "int256",
                        "name": "",
                        "type": "int256"
                    }
                ],
                "stateMutability": "view",
                "type": "function"
            }
        ]
            // Connect wallet
            const { provider, account } = await WalletConnector.connectWallet({chainId: 11155111});
        
            // Create contract instance
            const tokenContract = WalletConnector.createContract(
            provider,
            '0x1A9CD84b055255E14848A691828B54Ef477a818d', // Replace with actual token address
            Abi
            );
        
            // Read token balance
            const value = await tokenContract.read('get', []);
            console.log('Value Variable:', value);
            const value2 = await tokenContract.estimateGas('get', []);
            console.log('Gas Value:', value2);
            // Contract Interaction
            const txHash = await tokenContract.write('setValue', [
            500961
            ], {
            from: account,
            gasLimit: '300000'
            });
        
            console.log('Transfer tx hash:', txHash);
            }```