Last active
April 17, 2023 20:49
-
-
Save fabianekc/046c85036aeba3ac5eb3bef61525c426 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Import the required libraries | |
const Web3 = require('web3'); | |
// Create a new instance of the Web3 provider | |
const web3 = new Web3('https://bellecour.iex.ec'); | |
// Define the address of the smart contract and the ABI | |
const contractAddress = '0xF31A125fb44E0c2dca45c2665F272e9fc09f92AE'; | |
const contractAbi = [ | |
{ | |
"anonymous": false, | |
"inputs": [ | |
{ | |
"indexed": false, | |
"internalType": "string", | |
"name": "_data", | |
"type": "string" | |
} | |
], | |
"name": "DataStored", | |
"type": "event" | |
}, | |
{ | |
"inputs": [ | |
{ | |
"internalType": "string", | |
"name": "_data", | |
"type": "string" | |
} | |
], | |
"name": "StoreInLogs", | |
"outputs": [], | |
"stateMutability": "nonpayable", | |
"type": "function" | |
} | |
]; | |
// Create a new instance of the smart contract object | |
const contract = new web3.eth.Contract(contractAbi, contractAddress); | |
// Define the function to be called and its arguments | |
const functionName = 'StoreInLogs'; | |
const functionArgs = ["dummy"]; | |
// Send the transaction to the smart contract | |
contract.methods[functionName](...functionArgs).send({ | |
from: '0x372B49E90407eAda9A9bEcBBf29b8A0F841E22D2', // the address of the sender | |
gas: 0, // the maximum amount of gas to be used for the transaction | |
}) | |
.then((receipt) => { | |
console.log('Transaction receipt:', receipt); | |
}) | |
.catch((error) => { | |
console.error('Error:', error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment