dapp互助公排质押挖矿开发详情版丨dapp互助公排质押挖矿系统开发(方案及功能)丨dapp互助公排质押挖矿源码平台

简介:  智能合约是运行在区块链公链上的一种代码,该代码由Solidity编写,并通过区块链的智能合约虚拟机来执行,以达到对区块链编程的目标。可以将区块链公联理解为操作系统,Solidity是编写该操作系统应用程序的编程语言,智能合约虚拟机则是编程语言编译之后的代码运行环境。

  智能合约是运行在区块链公链上的一种代码,该代码由Solidity编写,并通过区块链的智能合约虚拟机来执行,以达到对区块链编程的目标。可以将区块链公联理解为操作系统,Solidity是编写该操作系统应用程序的编程语言,智能合约虚拟机则是编程语言编译之后的代码运行环境。

  var fs=require('fs');

  const fetch=require('node-fetch')

  var Web3=require('web3');

  const ethers=require('ethers');

  const infuraKey=fs.readFileSync("../.infuraKey").toString().trim();

  var ethRpcUrl=https://rinkeby.infura.io/v3/+infuraKey

  var web3=new Web3(ethRpcUrl);

  abi=[

  {

  "inputs":[],

  "name":"getValue",

  "outputs":[

  {

  "internalType":"uint256",

  "name":"",

  "type":"uint256"

  }

  ],

  "stateMutability":"view",

  "type":"function"

  },

  {

  "inputs":[

  {

  "internalType":"uint256",

  "name":"_value",

  "type":"uint256"

  }

  ],

  "name":"setValue",

  "outputs":[],

  "stateMutability":"nonpayable",

  "type":"function"

  }

  ]

  contractAddress="合约地址"

  pk="钱包私钥"

  userAccount="私钥对应的账户地址"

  main()

  .then(()=>process.exit(0))

  .catch(error=>{

  console.error(error);

  process.exit(1);

  });

  async function main(){

  await setValue();

  await getValue();

  }

  async function getNonce(account){

  let nonce=await web3.eth.getTransactionCount(account);

  console.log('nonce=',nonce)

  return nonce;

  }

  async function getValue(){

  //对方法进行sha3编码,然后取前四个字节

  //var methodSign=await web3.utils.keccak256("getValue()").substr(0,10);

  var methodSign=await web3.utils.keccak256("getValue()").substr(0,10);

  //console.log(methodSign)

  data=methodSign;

  //如果有入参,对入参进行编码

  //encodeParams=web3.eth.abi.encodeParameters(['uint256'],[456]);

  //拼接方法名和入参作为jsonrpc的params中的data字段的数据

  //data+=encodeParams.substr(2,encodeParams.length)

  console.log(data)

  //构造post请求的body参数

  var input={"jsonrpc":"2.0","id":3,"method":"eth_call","params":[{"to":contractAddress,"data":data},"latest"]}

  //http可以一次多个请求

  var inputs=[input,input]

  //发送post请求

  const resp=await fetch(ethRpcUrl,{

  method:"POST",

  body:JSON.stringify(inputs),

  headers:{

  "Content-Type":"application/json"

  }

  });

  var rpcResult=await resp.json();

  console.log(rpcResult[0].result)

  //用ethers包中的方法解析返回结果

  var ethersResult=await ethers.utils.defaultAbiCoder.decode(['uint256'],rpcResult[0].result)

  //用web3包中的方法解析防护结果

  var decodeResult=await web3.eth.abi.decodeParameters(['uint256'],rpcResult[0].result);

  console.log("vaule is"+ethersResult)

  console.log("value is"+decodeResult[0])

  }

  async function setValue(){

  //这里借用web3的方法对要发送的内容进行签名

  var contract=new web3.eth.Contract(abi,contractAddress);

  value=456;

  var encodeABI=contract.methods.setValue(value).encodeABI();

  var signResult=await web3.eth.accounts.signTransaction({

  gas:3000000,

  to:contractAddress,

  data:encodeABI,

  nonce:await getNonce(userAccount)

  },pk);

  console.log(signResult);

  rawTransaction=signResult.rawTransaction

  //构造post请求的body参数

  var input={"jsonrpc":"2.0","id":3,"method":"eth_sendRawTransaction","params":[rawTransaction]}

  console.log(input)

  var inputs=[input]

  //发送post请求

  const resp=await fetch(ethRpcUrl,{

  method:"POST",

  body:JSON.stringify(inputs),

  headers:{

  "Content-Type":"application/json"

  }

  });

  var rpcResult=await resp.json();

  console.log(rpcResult)

  }

相关文章
|
18天前
|
人工智能 区块链
dapp质押代币分红模式系统开发|指南需求|技术原理
Web3.0提出以来,就是一个包罗万象的术语,用于任何与下一代互联网相关的事情,即“去中心化的数字基础设施”。
|
18天前
|
存储 区块链
DAPP链游盲盒代币质押模式系统开发细节方案
区块链这种去中心化、防篡改的平台,完美地解决了这些问题
|
8月前
|
安全 数据管理 区块链
DApp盲盒游戏代币质押系统开发讲解方案
DApp智能合约去中心化软件功能具备了去中心化的储存,去中心化的治理,开源特性
|
8月前
|
存储 分布式计算 大数据
DAPP质押合约代币公排互助系统开发详情讲解
区块链和大数据都是新一代信息技术,它们的概念不同,应用领域也有着一定的区别
|
区块链
dapp质押挖矿系统开发设计概述
DApp(去中心化应用)质押挖矿系统是基于区块链技术构建的一种去中心化应用,它结合了质押和挖矿的概念,让用户可以通过质押代币来参与挖矿活动并获得相应的奖励。
|
JavaScript 前端开发 测试技术
区块链泰山众筹互助商城dapp系统开发合约定制(代币分红模式)技术分析
区块链泰山众筹互助商城dapp系统开发合约定制(代币分红模式)技术分析
|
安全 5G
dapp借贷理财挖矿开发案例丨dapp借贷理财挖矿系统开发(开发逻辑及方案)丨dapp借贷理财挖矿系统源码
  Blockchain is a distributed ledger that is open to all.It uses blockchain data structure to verify and store data,and uses cryptography to ensure the security of data transmission and access.It has the characteristics of decentralization,tamper-proof,transparency and openness.
|
区块链
智能合约互助公排流动性质押挖矿开发正式版丨智能合约互助公排流动性质押挖矿系统开发(详情开发及源码)
The universe is the successor of the mobile internet,and the doors of the virtual world and the real world have been opened.The metauniverse may become the new direction of the development of the Internet,and may also be the next form of the development of the digital economy.The exploration of the
|
存储 人工智能 物联网
DAPP/LP流动性质押挖矿互助公排模式系统开发详细,DAPP/LP流动性质押挖矿互助公排开发源码
依据计算机领域常用的形式化分层方法,元宇宙可以分为元网络、元系统、元服务、元场景和元空间五层架构。元网络包含了通信、存储、计算、网络等支撑性技术,为元宇宙提供底层基础设施;元系统以区块链为核心,集成大数据、云计算、人工智能、物联网、人机交互和信息安全等技术,为元服务提供系统级基础技术能力
|
安全 区块链 数据安全/隐私保护
阐述dapp智能合约代币预售流动性质押挖矿分红系统开发逻辑及流程源码
 Blockchain transactions use cryptography to ensure network security and verify transactions.People use computers to"mine"or solve complex mathematical equations to confirm every transaction on the network and add new blocks to the blockchain as the core of the system.Participants will receive crypt

热门文章

最新文章