smartcontracts

Regular, repeating, interaction between an oracle and a smart contract

青春壹個敷衍的年華 提交于 2021-02-11 12:27:09
问题 This is just an example. I'm building this dapp where I have a start date and an end date and every day I want to get a random number from an oracle. If at some point the sum of the numbers I get every day exceeds a threshold then an OK message returns to my backend. Let's assume we have a range of 7 days. Day 1: My backend sends a request to the "smart contract Number" and calls the requestOk () method. The smart contract Number calls the gethNumber () method of the oracle smart contract and

Regular, repeating, interaction between an oracle and a smart contract

醉酒当歌 提交于 2021-02-11 12:25:59
问题 This is just an example. I'm building this dapp where I have a start date and an end date and every day I want to get a random number from an oracle. If at some point the sum of the numbers I get every day exceeds a threshold then an OK message returns to my backend. Let's assume we have a range of 7 days. Day 1: My backend sends a request to the "smart contract Number" and calls the requestOk () method. The smart contract Number calls the gethNumber () method of the oracle smart contract and

encode three integers into single integer

非 Y 不嫁゛ 提交于 2021-02-10 09:40:07
问题 I have to encode 3 numbers into the same integer. I have these 3 measurements uint256 carLength; uint256 carWidth; uint256 carDepth; and i want to encode these 3 numbers into the same integer with the possibility to decode. My problem is that I'm not very experienced at this low level. i think about functions like this function encodeNumbers(uint256 a, uint256 b, uint256 c) public view returns(uint256); function decodeNumber(uint256) public view returns (uint256, uint256, uint256); advice on

How to deposit ether to an account using solidity and web3?

孤人 提交于 2021-01-29 05:49:21
问题 I am building a sample smart contract . I am trying to deposit ether from 1 account to another but the issue is amount is deducted from the sender's account but not able to deposit to receiver's account. Here is my contract code : pragma solidity ^0.5.0; contract ApprovalContract{ address public sender; address public receiver; function deposit(address _receiver) external payable { require(msg.value > 0); sender = msg.sender; receiver = _receiver; address payable _rec = receiver.make_payable(

Why can't I read this HashMap in a NEAR contract?

∥☆過路亽.° 提交于 2021-01-28 07:50:34
问题 I have a NEAR smart contract that keeps a HashMap of Veggie records. My most basic accessor method get_veggie(vid), which looks up and returns one Veggie record, passes unit tests but fails in the deployed contract. It panics with 'veggie does not exist' when I send one of the keys returned by another accessor method, get_veggie_keys(). // this method returns an array of u64 keys: pub fn get_veggie_keys(&self) -> Vec<TokenId> { self.veggies.keys().cloned().collect() } // but this method

How can we generate multiple random number in ethereum?

佐手、 提交于 2020-06-27 09:38:27
问题 I want my smart contract to return 7 or 8 UNIQUE random numbers ranging from 1 to 100 upon calling the contract. What can be the best approach to obtain such result? 回答1: Probably if you are trying to build roulettes, lotteries, and card games using the Ethereum blockchain, as the Ethereum blockchain is deterministic, it imposes certain difficulties for those who have chosen to write their own pseudo-random number generator (PRNG). Some Vulnerable Methods Currently Used If you are using the

Validate TRON address using solidity ecrecover

孤街醉人 提交于 2020-06-17 11:55:09
问题 I'm trying to validate a signed message using a smart contract running on the TRON network. I've tried a few different methods but all failed: Based on this article I've deployed the following smart contract: contract Verifier { function recoverAddr(bytes32 msgHash, uint8 v, bytes32 r, bytes32 s) returns (address) { return ecrecover(msgHash, v, r, s); } function isSigned(address _addr, bytes32 msgHash, uint8 v, bytes32 r, bytes32 s) returns (bool) { return ecrecover(msgHash, v, r, s) == _addr

Send ERC20 token with web3

时光怂恿深爱的人放手 提交于 2020-01-08 16:26:42
问题 I'm currently using 0.2x.x version of Web3 Javascript API. I deployed my custom ERC20 token by creating smart contract in solidity (on REMIX IDE). I installed the MetaMask and had a test on https://wallet.ethereum.org/ to send some custom ERC token to another my account. It worked well. I want to add the 'send custom ERC20 Token' function in my javascript code using Web3. Here is my code below. var http = require('http'); var Web3 = require('web3'); var Tx = require('ethereumjs-tx'); var abi

Send ERC20 token with web3

大憨熊 提交于 2020-01-08 16:25:10
问题 I'm currently using 0.2x.x version of Web3 Javascript API. I deployed my custom ERC20 token by creating smart contract in solidity (on REMIX IDE). I installed the MetaMask and had a test on https://wallet.ethereum.org/ to send some custom ERC token to another my account. It worked well. I want to add the 'send custom ERC20 Token' function in my javascript code using Web3. Here is my code below. var http = require('http'); var Web3 = require('web3'); var Tx = require('ethereumjs-tx'); var abi

Solidity - Solidity code to Input JSON Description

我是研究僧i 提交于 2020-01-02 09:52:41
问题 I want to compile my ehtereum HelloWorld.sol smart contract. In all the tutorials is that you do it like this: var solc = require('solc'); var compiledContract = solc.compile(fs.readFileSync('HelloWorld.sol').toString(); where HelloWorld.sol is: pragma solidity ^0.5.1; contract HelloWorld { bytes32 message; constructor(bytes32 myMessage) public { message = myMessage; } function getMessage() public view returns(bytes32){ return message; } } In other words I put my raw Solidity contract code