当前位置: 首页 > news >正文

网站建设制作中国龙岩网

网站建设制作,中国龙岩网,做网站备案的公司,做网站项目如何实现支付Web3Network.eth.sendSignedTransaction(serializedTx) 参数#xff1a; from- String|Number#xff1a;发送帐户的地址。如果未指定#xff0c;则使用web3.eth.defaultAccount属性。或web3.eth.accounts.wallet中本地的地址。 to- String:(可选#xff09;消息的目标地址… Web3Network.eth.sendSignedTransaction(serializedTx) 参数 from- String|Number发送帐户的地址。如果未指定则使用web3.eth.defaultAccount属性。或web3.eth.accounts.wallet中本地的地址。 to- String:(可选消息的目标地址若未定义则为发送消息。 value- Number|String|BN|BigNumber:(可选为wei中的交易转移的数量如果是发送消息则是捐赠给地址。 gas - Number:(可选默认待定用于交易的gas未使用的gas会退还。 gasPrice- Number|String|BN|BigNumber:(可选此交易的gas价格以wei为单位默认为web3.eth.gasPrice。 data- String:(可选包含合同上函数调用数据的ABI字节字符串。 nonce- Number:(可选随机数的整数。 EthPayApi 介绍实现流程一共分为两部分一完成Api参数、二完成privateKey加密发起Pay 初始化 npm install web3 script setup nameEthPay import Web3 from web3const Web3Network new Web3(Web3.givenProvider || wss://goerli.infura.io/ws/v3/xxx ) /script wss://goerli.infura.io/ws/v3/xxx 网络节点需要替换为自己的网络节点如果拿到自己网络节点查看【Web3】Web3连接到以太坊网络测试网、主网_春暖花开.,的博客-CSDN博客 一.Api参数 定义自己Eth账号 //钱包地址 const walletAddress ref(你的ETh地址) //钱包私钥 const walletPrivateKey ref(你的Eth私钥 ) 参数一共分为 form //发送方地址     nonce //发送方交易次数     gasPric //预估手续费 to //接收方地址     value //以wei单位数量    data //转Token代币会用到的一个字段 gas //用于交易gas 1.nonce transaction次数 //transaction次数const numberTransaction await Web3Network.eth.getTransactionCount(walletAddress.value) 2.gasPric 获取预计手续费 //获取预计手续费 const serviceCharge await Web3Network.eth.getGasPrice()3. value 数量 //以wei为单位数量 const WeiMoney Web3.utils.toWei(0.0001) 4.合并 const rawTx {form: walletAddress.value, //发送方地址nonce: numberTransaction, //发送方交易次数gasPrice: serviceCharge, //预估手续费to: xxx, //接收方地址value: WeiMoney, //以wei单位数字data: 0x00 //转Token代币会用到的一个字段} 5.gas  //把交易数据进行gas计算const gas await Web3Network.eth.estimateGas(rawTx)rawTx.gas gas 二.privateKey加密调用sendSignedTransaction函数 1.私钥转数组十六进制 为什么转换 因为 tx.sign() 要求长度必须在32位以内所以需要转换 npm install buffer import { Buffer } from buffer//把privateKey转换 数组hexconst PrivatekeyHex Buffer(walletPrivateKey.value, hex)console.log(key, PrivatekeyHex) 2.ethereumjs-tx 库加密转换数组十六进制后Eth私钥 注意tx.sign( ) 要求长度必须32位以内 npm install ethereumjs-tx1.3.7 import Tx from ethereumjs-tx //privateKey加密const tx new Tx(rawTx)tx.sign(PrivatekeyHex)//通过ethereumjs-tx加密并转为十六进制字符串const serializedTx 0x tx.serialize().toString(hex)console.log(serializedTx) 3.如果出现这样报错 error  in ./node_modules/cipher-base/index.js Module not found: Error: Cant resolve stream in C:\Users\ttatt\Desktop\前端\xxx\xxx\Web3\Web3实战\web3defivue\node_modules\cipher-base BREAKING CHANGE: webpack 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to:         - add a fallback resolve.fallback: { stream: require.resolve(stream-browserify) }         - install stream-browserify If you dont want to include a polyfill, you can use an empty module like this:         resolve.fallback: { stream: false } ERROR in ./node_modules/cipher-base/index.js 3:16-43 Module not found: Error: Cant resolve stream in C:\Users\ttatt\Desktop\xxx\xxx\85期\Web3\Web3实战\web3defivue\node_modules\cipher-base BREAKING CHANGE: webpack 5 used to include polyfills for node.js core modules by default. This is no longer the case. Verify if you need this module and configure a polyfill for it. If you want to include a polyfill, you need to:         - add a fallback resolve.fallback: { stream: require.resolve(stream-browserify) }         - install stream-browserify If you dont want to include a polyfill, you can use an empty module like this:         resolve.fallback: { stream: false }   ./node_modules/create-hash/browser.js 7:11-33   ./node_modules/ethereumjs-util/dist/index.js 18:17-39   ./node_modules/ethereumjs-tx/es5/index.js 9:14-40   ./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/vue-loader/dist/index.js??ruleSet[0].use[0]!./src/App.vue?vuetypescriptsetuptruenameweb3langjs 4:0-31 68:21-23 88:15-17   ./src/App.vue?vuetypescriptsetuptruenameweb3langjs 1:0-210 1:0-210 1:211-410 1:211-410   ./src/App.vue 2:0-75 3:0-70 3:0-70 6:49-55   ./src/main.js 2:0-28 6:22-25 webpack compiled with 1 error 要解决在 vue.config.js npm install node-polyfill-webpack-plugin2.0.1 const { defineConfig } require(vue/cli-service) // 引入插件 const NodePolyfillWebpackPlugin require(node-polyfill-webpack-plugin)module.exports defineConfig({transpileDependencies: true,configureWebpack: {//使用插件plugins: [new NodePolyfillWebpackPlugin()]} }) 4.调用ETHPay函数sendSignedTransaction 开始EthPay是否成功 //开始执行const Transfer Web3Network.eth.sendSignedTransaction(serializedTx)// 监听是否成功 -- 加载中Transfer.on(transactionHash, txid {console.log(查看----https://goerli.etherscan.io/tx/${txid})}) 代码 //一.第一部分//transaction次数const numberTransaction await Web3Network.eth.getTransactionCount(walletAddress.value)console.log(numberTransaction)//获取预计手续费const serviceCharge await Web3Network.eth.getGasPrice()console.log(serviceCharge)//以wei为单位数量const WeiMoney Web3.utils.toWei(0.0001)console.log(WeiMoney)//Api参数const rawTx {form: walletAddress.value, //发送方地址nonce: numberTransaction, //发送方transaction次数gasPrice: serviceCharge, //预估手续费to: xxxx, //接收方地址value: WeiMoney, //以wei单位数量data: 0x00 //转Token会用到的一个字段}//把transaction数据进行gas计算const gas await Web3Network.eth.estimateGas(rawTx)rawTx.gas gas//二.第二部分//把privateKey转换 数组hex//因为 tx.sign() 要求长度必须在32位以内所以需要转换const PrivatekeyHex Buffer(walletPrivateKey.value, hex)console.log(key, PrivatekeyHex)//privateKey加密const tx new Tx(rawTx)tx.sign(PrivatekeyHex)//通过ethereumjs-tx加密并转为十六进制字符串const serializedTx 0x tx.serialize().toString(hex)//开始执行const Transfer Web3Network.eth.sendSignedTransaction(serializedTx)// 监听是否成功 -- 加载中Transfer.on(transactionHash, txid {console.log(txid)console.log(查看----https://goerli.etherscan.io/tx/${txid})})
http://www.huolong8.cn/news/434647/

相关文章:

  • 化妆品网站优势电影网站做淘客
  • 个人做淘宝客网站好做吗ui设计的基本流程图
  • 网站顶部展出的大幅广告一键logo
  • 网站建设seo需求文档WordPress微信强制跳转插件
  • 网站建设开放的端口专注大连网站建设
  • 百度网站快速收录托者设计吧官网
  • 苏州市相城区建设局网站深圳网站专业制作
  • 泸西县建设小学网站企业电子商务网站建设评估试验
  • WordPress建影视站买国外域名 网站
  • 杭州cms模板建站网页设计师培训大全
  • 厦门哪些做鲜花的网站如何网上建设网站
  • wordpress网站新闻织梦网站后台密码忘记
  • 提供邢台做wap网站免费网站域名空间
  • asp.net程序做的网站安全吗长域名的优秀网站
  • 长沙服务专业的建网站python做的大型网站
  • 网站首页浮动窗口代码大都会app用不了
  • windowxp做网站服务器wordpress 语言切换
  • 前端代码大全台州seo排名优化
  • 复旦大学精品课程网站旅游网站的设计的前提
  • 高端的的网站建设公司开票开网站建设费
  • 站长工具查询seowordpress控制字数
  • 邢台市网站开发公司有哪些颐和国际沧州网络科技
  • 电商网站建设优缺点免费招聘网站平台有哪些
  • 资阳地网站seo福州网红打卡景点
  • 网站建设图片教程网站建设模板研究
  • 重庆网站备案查询系统华强北ic网站建设
  • 东莞市房管局官方网站杭州网站建设方案
  • 苏州网站建设推广咨询平台wordpress使用redis
  • 酷维网站模版wordpress网站添加背景音乐
  • 面包店网站建设规划书提高工作效率的方法不正确的是