Client libraries
Metacces uses Geth which supports common smart contract and dapp development, deployment, and operational use cases, using tools such as , and . The client supports common methods, for example eth, net, web3, debug, and miner.
Prerequisites
web3
The library is the most widely used for developing applications.
Install web3 in your project
npm install web3
Initialize the web3 client
Initialize your client where:
https://oli.accesscan.io is the JSON-RPC HTTP endpoint of your Metacces node.
Example connection
const Web3 = require("web3");
const web3 = new Web3("http://oli.accesscan.io");
WS example
Example connection
const Web3 = require("web3");
const web3 = new Web3("http://ws.accesscan.io");
Copy myContract.deploy({
data: '0x12345...',
arguments: [123, 'My String']
})
.send({
from: '0x1234567890123456789012345678901234567891',
gas: 1500000,
gasPrice: '30000000000000'
}, function(error, transactionHash){ ... })
.on('error', function(error){ ... })
.on('transactionHash', function(transactionHash){ ... })
.on('receipt', function(receipt){
console.log(receipt.contractAddress) // contains the new contract address
})
.on('confirmation', function(confirmationNumber, receipt){ ... })
.then(function(newContractInstance){
console.log(newContractInstance.options.address) // instance with the new contract address
});
Copy const rawTxOptions = {
nonce: "0x00",
from: account.address,
to: null, //public tx
value: "0x00",
data: "0x" + contractBin + contractConstructorInit,
gasPrice: "0x0", //ETH per unit of gas
gasLimit: "0x24A22", //max number of gas units the tx is allowed to use
};
console.log("Creating transaction...");
const tx = new Tx(rawTxOptions);
console.log("Signing transaction...");
tx.sign(Buffer.from(account.privateKey.substring(2), "hex"));
console.log("Sending transaction...");
var serializedTx = tx.serialize();
const pTx = await web3.eth.sendSignedTransaction(
"0x" + serializedTx.toString("hex").toString("hex"),
);
console.log("tx transactionHash: " + pTx.transactionHash);
console.log("tx contractAddress: " + pTx.contractAddress);
return pTx;