I deployed the smart contract into a test network. so if a new user is added to the test network and he wants to use my smart contract functions. How to call those functions by the new user in the test network
1 Answer
Using web3.js v1, you can do something like this:
let fs = require("fs");
let Web3 = require("web3");
async function run() {
let web3 = new Web3(YOUR_ETHEREUM_NODE_ADDRESS);
let abi = fs.readFileSync("YourContract.abi").toString();
let contract = new web3.eth.Contract(JSON.parse(abi), YOUR_DEPLOYED_CONTRACT_ADDRESS);
let transaction = contract.methods.yourMethod(yourArguments);
let options = {
to : transaction._parent._address,
data: transaction.encodeABI(),
gas : await transaction.estimateGas({from: YOUR_PUBLIC_KEY}),
};
let signedTransaction = await web3.eth.accounts.signTransaction(options, YOUR_PRIVATE_KEY);
let transactionReceipt = await web3.eth.sendSignedTransaction(signedTransaction.rawTransaction);
return transactionReceipt;
}
-
where should I use this because I am using geth console. Is it possible to call the functions from geth console by other nodes in the network?– vijjuCommented Jul 17, 2018 at 7:32
-
You can run it on your machine with NodeJS as a separate process (i.e., put it in
myScript.js
and callnode myScript.js
). Commented Jul 17, 2018 at 11:38