Build a client for your contract
Step 1: Set Up Your Project
mkdir iotex-client
cd iotex-client
npm init -y
npm install web3Step 2: Connect to the IoTeX Testnet
const { Web3 } = require('web3');
const web3 = new Web3('https://babel-api.testnet.iotex.io');Step 3: Prepare Contract Details
const contractAddress = 'YOUR_DEPLOYED_CONTRACT_ADDRESS';
const abi = [
{
"anonymous": false,
"inputs": [
{ "indexed": false, "internalType": "address", "name": "sender", "type": "address" },
{ "indexed": false, "internalType": "string", "name": "message", "type": "string" }
],
"name": "MessagePosted",
"type": "event"
},
{
"inputs": [
{ "internalType": "string", "name": "message", "type": "string" }
],
"name": "postMessage",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
];
const contract = new web3.eth.Contract(abi, contractAddress);Step 4: Send a Message
Last updated

