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)

  }

相关文章
|
4月前
|
存储 区块链
DAPP链游盲盒代币质押模式系统开发细节方案
区块链这种去中心化、防篡改的平台,完美地解决了这些问题
|
11月前
|
存储 算法 区块链
DAPP持币生息系统开发|去中心化质押系统开发
每个区块链都遵循统一的规则,其规则是基于密码算法而不是信用证书,数据更新过程需要客户的允许
|
算法 区块链
Defi质押挖矿系统开发源码二开示例
开发一个DeFi质押挖矿系统需要一定的技术知识和经验,如果您有一定的技术基础和开发经验,可以考虑对开源代码进行二次开发。以下是一些可用于DeFi质押挖矿系统二次开发的开源代码:
|
区块链
dapp质押挖矿系统开发设计概述
DApp(去中心化应用)质押挖矿系统是基于区块链技术构建的一种去中心化应用,它结合了质押和挖矿的概念,让用户可以通过质押代币来参与挖矿活动并获得相应的奖励。
|
存储 边缘计算 网络协议
关于智能合约DAPP流动性质押挖矿分红系统开发实现技术原理及详情
Web3.0这个名字出现得比区块链更早。但在区块链兴起之前,Web3.0因缺乏解决方案只能停留在概念阶段。随着区块链技术的发展和加密货币投资者的增多,以太坊、Polkadot等区块链生态中涌现出一批与Web3.0相关的项目。因此,区块链技术奠定了Web3.0发展的基础。就整个区块链行业而言,多链并存的格局还会持续很长时间。在这种情况下,不同区块链生态的Web3.0用户有进行交互的需求,跨链技术会在这个过程中发挥重要作用。
关于智能合约DAPP流动性质押挖矿分红系统开发实现技术原理及详情
|
存储 人工智能 边缘计算
什么是DAPP智能合约系统开发?DAPP智能合约流动性质押挖矿分红逻辑系统开发详情方案及设计
  Web 3.0:指的移动互联网后的下一个阶段的互联网生态,主要是通过区块链等技术手段,实现去中心化的网络形态,实现模拟真实世界感受、打破虚拟、现实边界的互联网;
什么是DAPP智能合约系统开发?DAPP智能合约流动性质押挖矿分红逻辑系统开发详情方案及设计
|
存储 前端开发 JavaScript
浅谈DAPP智能合约流动性质押挖矿分红系统开发技术分析及代码部署
“Web3.0”是一个用户共建、隐私保护、平台开放的生态体系。相比“Web2.0”,“Web3.0”的目标是实现一个更加开放、零信任或是低信任、无许可的价值互联网时代。其生态体系主要由“Web3.0钱包”、“稳定币”、“公链”、“NFT”、“GameFi”、“去中心化存储”、“Dapp”、“DAO”、“DeFi”构成。
浅谈DAPP智能合约流动性质押挖矿分红系统开发技术分析及代码部署
|
供应链 区块链 数据安全/隐私保护
什么是智能合约?质押借贷理财挖矿dapp系统开发案例源代码详情
什么是智能合约?质押借贷理财挖矿dapp系统开发案例源代码详情
|
区块链
智能合约互助公排流动性质押挖矿开发正式版丨智能合约互助公排流动性质押挖矿系统开发(详情开发及源码)
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