写点什么

区块链项目开发技术团队源码交付

  • 2023-02-09
    广东
  • 本文字数:563 字

    阅读完需:约 2 分钟

区块链项目开发咨询薇 hkkf5566,NFT 代币铸造,元宇宙链游开发,LP 质押,defi 挖矿,dapp 定制,swap 开发等

获取链信息 const Web3 = require('web3')

async function getChainId() {

const web3 = new Web3('https://http-mainnet.hecochain.com')let chainId = await web3.eth.getChainId()console.log(`chain id: ${chainId}`)return chainId
复制代码

}

生成账户 const Web3Accounts = require('web3-eth-accounts')

let account = new Web3Accounts().create()//do not do this on prd envconsole.log(account generated. address: ${account.address}, private key: ${account.privateKey})

建立交易 const Web3 = require('web3')

async function transfer(fromAccount, to, value){

const web3 = new Web3('https://http-mainnet.hecochain.com')let chainId = await web3.eth.getChainId()let nonce = await web3.eth.getTransactionCount(fromAccount.address)let gasPrice = await web3.eth.getGasPrice()
let unsigned = { from: fromAccount.address, to, value: web3.utils.numberToHex(web3.utils.toWei(value, 'ether')), gasPrice, nonce, chainId,}
unsigned.gas = await web3.eth.estimateGas(unsigned)
let signed = await fromAccount.signTransaction(unsigned)return signed
复制代码

}

用户头像

还未添加个人签名 2022-05-23 加入

区块链项目开发,咨询weixin:hkkf5566

评论

发布
暂无评论
区块链项目开发技术团队源码交付_开发微hkkf5566_InfoQ写作社区