Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
* RPC: https://rpc.tomochain.com mainnet, https://testnet.tomochain.com testnet
* chainId: 88 mainnet, 89 testnet
* Owner address: balance at least 50000 TOMO
* Coinbase is node address. You can create a empty wallet with https://wallet.testnet.tomochain.com
*/
const rpc = 'https://testnet.tomochain.com'
chainId = 89
const pkey = '[OWNER_PKEY]' // include 0x
const coinbase = "[YOUR_COINBASE_ADDRESS]"
const Web3 = require('web3');
const web3 = new Web3(rpc);
const account = web3.eth.accounts.privateKeyToAccount(pkey)
const owner = account.address
web3.eth.accounts.wallet.add(account)
web3.eth.defaultAccount = owner
// https://raw.githubusercontent.com/tomochain/tomomaster/master/abis/TomoValidatorAbi.json
const validatorAbi = require('./TomoValidatorAbi.json')
const address = '0x0000000000000000000000000000000000000088'
const validator = new web3.eth.Contract(validatorAbi,
address, {gasPrice: 250000000, gas: 2000000 })
validator.methods.propose(coinbase).send({
from: owner,
value: '50000000000000000000000', // 50K TOMO
gas: 2000000,
gasPrice: 250000000,
chainId: chainId
})
.then((result) => {
console.log('Propose a new node', result)
// stake 500 TOMO to node
return validator.methods.vote(coinbase).send({
from: owner,
value: '500000000000000000000', // 500 TOMO
gas: 2000000,
gasPrice: 250000000,
chainId: chainId
})
.then((result) => {
console.log('Stake to a node', result)
}).catch(e => console.log(e))
}).catch(e => console.log(e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.