blockwizard
v1.0.2
Published
Simple and Easy to use Web3 SDK
Downloads
1
Readme
BlockWizard (Made by Sourav Maji)
Simple and Easy to use Web3 SDK
Documentation
Steps to Call Write Smart Contract Function in your Frontend:
- Initialize The SDK:
const ethereumSDK = new BlockWizard();
- Call the function:
const writeFunctionTest = async () => { try {
ethereumSDK.connectWallet();
ethereumSDK.setContract(contractAddress, contractABI);
// Call the write function (without value or arguments)
const transactionHash = await ethereumSDK.callWriteFunction('mint',undefined, [connectedAddress,"1000000"]);
console.log('Write Transaction Hash:', transactionHash);
} catch (error) {
setSdkError(error.message);
}
};
Usage/Examples
// YourNextJSComponent.js
import { useState } from 'react';
import BlockWizard from 'BlockWizard';
const YourNextJSComponent = () => {
const [connectedAddress, setConnectedAddress] = useState(null);
const [sdkError, setSdkError] = useState(null);
const [smartContractSource, setSmartContractSource] = useState('');
const [contractAddress, setContractAddress] = useState('');
const ethereumSDK = new BlockWizard();
const connectWallet = async () => {
try {
const address = await ethereumSDK.connectWallet();
setConnectedAddress(address);
} catch (error) {
setSdkError(error.message);
}
};
const deployContract = async () => {
try {
// Deploy the smart contract using your SDK
const deployedContractAddress = await ethereumSDK.deploySmartContract(smartContractSource);
setContractAddress(deployedContractAddress);
} catch (error) {
setSdkError(error.message);
}
};
const writeFunctionTest = async () => {
try {
// Set the contract details in the SDK
ethereumSDK.connectWallet();
const contractAddress = "0x921a4B906EF4Da0951ec91A15789A9Ff59144238";
const contractABI = [
{
"type": "function",
"name": "mint",
"inputs": [
{
"type": "address",
"name": "to",
"internalType": "address"
},
{
"type": "uint256",
"name": "amount",
"internalType": "uint256"
}
],
"outputs": [],
"stateMutability": "nonpayable"
}
];
ethereumSDK.setContract(contractAddress, contractABI);
// Call the write function (without value or arguments)
const transactionHash = await ethereumSDK.callWriteFunction('mint',undefined, [connectedAddress,"1000000"]);
console.log('Write Transaction Hash:', transactionHash);
} catch (error) {
setSdkError(error.message);
}
};
return (
<div>
<h1>Your Next.js Component</h1>
<button onClick={connectWallet}>Connect wallet</button>
<br />
{connectedAddress && <p>Connected Address: {connectedAddress}</p>}
<div style={{ marginTop: '1.5rem' }}>
<label>
Enter Smart Contract Source Code:
<textarea
rows="8"
value={smartContractSource}
onChange={(e) => setSmartContractSource(e.target.value)}
placeholder="Enter your smart contract source code here..."
style={{
width: '100%',
background: 'white',
border: '2px solid #ccc',
color: 'black',
borderRadius: '4px',
padding: '8px',
marginTop: '8px',
}}
/>
</label>
</div>
<button onClick={deployContract}>
Deploy Contract
</button>
<br></br>
<button onClick={writeFunctionTest}>
Write contract
</button>
{contractAddress && (
<div style={{ marginTop: '1rem' }}>
<p>Contract Address: {contractAddress}</p>
</div>
)}
{sdkError && <p>Error: {sdkError}</p>}
</div>
);
};
export default YourNextJSComponent;