cron - 从智能合约安排通话功能
问题描述
我希望每次从我的智能合约中运行我的农场功能。如何处理每 3 小时运行一次该功能?
解决方案
该语言没有实现本地方式,因为 Solidity 函数是作为事务的结果执行的。但您可以安排每 3 小时发送一次交易。
其中一种方法是使用 Chainlink 作业的 cron 启动器。
带有作业配置示例的文档:
或者在您的服务器上运行直接发送交易的脚本(不使用 Chainlink 作为中介)。
const Web3 = require('web3');
const web3 = new Web3(providerUrl);
const myContract = new web3.eth.Contract(jsonAbi, contractAddress);
web3.eth.accounts.wallet.add(senderPrivateKey);
async function sendTransaction() {
myContract.methods.myFunction().send({from: senderAddress});
}
setInterval('sendTransaction', 3 * 60 * 60 * 1000); // 3 hours in milliseconds
推荐阅读
- python - 自定义 Jupyter 单元格格式?
- python - 通过 Func 动画后重复 sns 热图的传说
- php - 如何在 WooCommerce 中的“添加到购物车”按钮下移动星级评分
- html - 从 iphone (Safari 和 Chrome) 上的第一个字段而不是最后一个字段发送表单
- amazon-web-services - 在 aws 工作区与 ec2 实例上托管 rest-api 服务器?
- php - 在php中迭代关联数组不会打印出值
- php - 难以让 Mongodb 使用 PHP
- python - 如何将列表转换为 HTML 表格?
- java - 带有小数秒的 Java 时间戳
- php - 使用闰年的php中两个日期之间的差异