Web3 opertor is combined with web3 library for easily to interact with Ethereum
- Web3 Operator
- Usage
- Account_operation
- Contract_interaction
compiles(contract)
privateKeyDeploy(bytecode, privateKey)
accountDeploy(bytecode, from, password)
readContract(contractAddress, abi, method, parameters)
accountWriteContract(from, contractAddress, abi, method, parameters, value, password)
privateKeylWriteContract(contractAddress, abi, method, parameters, value, privateKey)
accountToLoopWriteContract(from, contractAddress, abi, method, parameters, value, password, loopTime, endTime)
privateKeyToLoopWriteContract(contractAddress, abi, method, parameters, value, privateKey, loopTime, endTime)
ListeningEvent(type, host, port)
- Create contract store directory
$ mkdir contract
- import module
const Web3operator = require('web3-operator');
const web3operator = new Web3operator(web3_rpc);
create account by random number
random
-String
: random string
web3operator.createAccount(random)
/*
> return {
address: ...,
privateKey: ...,
signTransaction: function(tx){...},
sign: function(data){...},
encrypt: function(password){...}
}
*/
query account by private key
privateKey
-String
: private key
web3Operator.queryAccount(privateKey)
/*
> return {
address: ...,
privateKey: ...,
signTransaction: function(tx){...},
sign: function(data){...},
encrypt: function(password){...}
}
*/
decrypt account by account keyStoreJson and account password
keyStoreJson
-Object
if your account created in local node, it should store in ./node/keyStorepassword
-String
: sender account password
web3Operator.decryptAccount(keyStoreJson, password)
/*
> return {
address: ...,
privateKey: ...,
signTransaction: function(tx){...},
sign: function(data){...},
encrypt: function(password){...}
}
*/
encrypt account by account keyStoreJson and account password
privateKey
-String
: private keypassword
-String
: sender account password
web3Operator.encryptAccount(privateKey, password)
// > return keyStoreJson
import private key to node , that will convert to keyStoreJson
privateKey
-String
: private keypassword
-String
: sender account password
web3Operator.importKey(privateKey, password)
// >
compile contract from ./contract
directory
contract
-String
: contract name
web3Operator.compiles(contract)
// > return abi and bytecode
use private key to deploy contract
bytecode
-String
: contract bytecodeprivateKey
-String
: private key
web3Operator.privateKeyDeploy(bytecode, privateKey)
// > return transaction receipt , recommand to find contractAddress of attribute for contract interaction
use account address and password to deploy contract
bytecode
-String
: contract bytecodefrom
-Address
: sender account addresspassword
-String
: sender account password
web3Operator.accountDeploy(bytecode, from, password)
// > return transaction receipt , recommand to find contractAddress of attribute for contract interaction
read indicate contract method
contractAddress
-String
: contract addressabi
-Array
: contract abimethod
-String
: contract function nameparameters
-Array
: contract function parameters
web3Operator.readContract(contractAddress, abi, method, parameters)
// > return contract data
use account address and password to write contract
from
-Address
: sender account address, meancontractAddress
-String
: contract nameabi
-Array
: contract abimethod
-String
: contract function nameparameters
-Array
: contract function parametersvalue
-Number
: ether valuepassword
-String
: sender account password
web3Operator.accountWriteContract(from, contractAddress, abi, method, parameters, value, password)
// > return transaction receipt
use private key to write contract
contractAddress
-String
: contract nameabi
-Array
: contract abimethod
-String
: contract function nameparameters
-Array
: contract function parametersvalue
-Number
: ether valueprivateKey
-String
: private key
web3Operator.privateKeylWriteContract(contractAddress, abi, method, parameters, value, privateKey)
// > return transaction receipt
accountToLoopWriteContract(from, contractAddress, abi, method, parameters, value, password, loopTime, endTime)
use private key to write contract for loop before endTime, after respond the amount of confirmed transaction
from
-Address
: sender account address, meancontractAddress
-String
: contract nameabi
-Array
: contract abimethod
-String
: contract function nameparameters
-Array
: contract function parametersvalue
-Number
: ether valuepassword
-String
: sender account passwordloopTime
-Number
: send transaction in loopendTime
-Number
: the time for finish loop send transaction process
web3Operator.accountToLoopWriteContract(from, contractAddress, abi, method, parameters, value, password, loopTime, endTime)
// > return true
privateKeyToLoopWriteContract(contractAddress, abi, method, parameters, value, privateKey, loopTime, endTime)
use private key to write contract for loop before endTime, after respond the amount of confirmed transaction
contractAddress
-String
: contract nameabi
-Array
: contract abimethod
-String
: contract function nameparameters
-Array
: contract function parametersvalue
-Number
: ether valueprivateKey
-String
: private keyloopTime
-Number
: send transaction in loopendTime
-Number
: the time for finish loop send transaction process
web3Operator.privateKeyToLoopWriteContract(contractAddress, abi, method, parameters, value, privateKey, loopTime, endTime)
// > return true
listening specific event
type
-String
can belogs
、pendingTransactions
、syncing
host
-String
websocket hostport
-String
websocket port
web3Operator.ListeningEvent(type, host, port)
// > listening