Chainlink VRF : Error encoding arguments: Error: invalid BigNumber string - solidity

I'm trying to get a random number with Chainlink VRF,
So Hi have follow this demo step by step : https://www.youtube.com/watch?v=JqZWariqh5s
here is what i've copied on Remix :
pragma solidity 0.6.6;
import "https://raw.githubusercontent.com/smartcontractkit/chainlink/master/evm-contracts/src/v0.6/VRFConsumerBase.sol";
contract RandomNumberConsumer is VRFConsumerBase {
bytes32 public keyHash;
uint256 public fee;
uint256 public randomResult;
constructor() VRFConsumerBase(
0xdD3782915140c8f3b190B5D67eAc6dc5760C46E9, // VRF Coordinator
0xa36085F69e2889c224210F603D836748e7dC0088 // LINK Token
) public
{
keyHash = 0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4;
fee = 0.1 * 10 ** 18; // 0.1 LINK
}
function getRandomNumber(uint256 userProvidedSeed) public returns (bytes32 requestId) {
return requestRandomness(keyHash, fee, userProvidedSeed);
}
function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override {
randomResult = randomness.mod(50).add(1);
}
}
when i click on getRandomNumber, i always get this error :
Error encoding arguments: Error: invalid BigNumber string (argument="value", value="", code=INVALID_ARGUMENT, version=bignumber/5.0.8)
and with the fulfillRandomness, i get this error :
Error encoding arguments: Error: invalid arrayify value (argument="value", value="", code=INVALID_ARGUMENT, version=bytes/5.0.5)

Add some seed number into the function, and then click it.
Also, be sure to fund it with LINK.
Also, fulfillRandomness is only callable by the Chainlink VRF, so no worries on that part.

It looks like you are not passing the userProvidedSeed as an argument to getRandomNumber()
Try putting any number into the box beside the getRandomNumber method in Remix and then click on the method.
Also, fulfillRandomness is only callable by the Chainlink VRF, so do no worry about calling that function.

Related

Unable to compile smart contracts

I am learning the tutorials in 「Mastering Ethereum: Building Smart Contracts and DApps」(O'Reilly)
I copied the following sample code and created a solidity contract(METoken.sol).
Next, I compiled it with the「truffle compile」 command, but it gave me an error.Please assist, thanks
//Error Message
TypeError: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
// METoken.sol
pragma solidity ^0.4.21;
import 'openzeppelin-solidity/contracts/token/ERC20/StandardToken.sol';
contract METoken is StandardToken {
string public constant name = 'Mastering Ethereum Token';
string public constant symbol = 'MET'; uint8 public constant decimals = 2; uint constant
_initial_supply = 2100000000;
function METoken() public {
totalSupply_ = _initial_supply;
balances[msg.sender] = _initial_supply;
emit Transfer(address(0), msg.sender, _initial_supply);
}
}
The Standard token was renamed to ERC20.sol in openzeppelin contracts 2.0 version.
You have to modify your imports , then the contract will get compile.
Refer..
https://github.com/OpenZeppelin/openzeppelin-contracts/issues/1557

testing solidity - Error: invalid BigNumber value, when passing object as argument

I have a function in my Solidity which takes a struct as first parameter:
function mintGenesisAnimal(AnimalInfo memory _animalInfo, string memory _tokenUri) onlyOwner public {
// ...
}
but when I'm trying to test this function with the code below:
const animalInfo = {
raceName: 'Tiger',
}
await Animal.mintGenesisAnimal(animalInfo, 'https://google.com')
The test fails with a weird issue relative to "BigNumber":
Error: invalid BigNumber value (argument="value", value=undefined, code=INVALID_ARGUMENT, version=bignumber/5.6.0)
Why is a BigNumber reported when I'm trying to pass a struct (js object) as parameter ?

Require() function is not working properly in below code

Deployed this contract on Remix IDE on InjectedWeb3 environment on Rinkeyby test network.
I tried removing the error msg statement in require, then it is not throwing error but still not working properly i.e the function is getting executed irrespective of any require condition.
pragma solidity >=0.4.22 <0.7.0;
contract RegisterLand{
struct land{
uint area;
string location;
uint floorsAllowed;
mapping(uint => address) owner;
uint count;
bool idExists;
}
mapping(uint => land) lands;
function Register(uint id,uint area, string memory location, uint
floorsAllowed) public
{
require(
!lands[id].idExists,
"ID already exists"
);
lands[id] = land(area, location, floorsAllowed,0,true);
lands[id].owner[lands[id].count] = msg.sender;
}
function ViewLand(uint id) public view returns(address currentOwner,
uint
landArea, string memory landLocation, uint landFloors )
{
require(lands[id].idExists,
"Id doesn't exist.");
currentOwner = lands[id].owner[lands[id].count];
landArea = lands[id].area;
landLocation = lands[id].location;
landFloors = lands[id].floorsAllowed;
}
}
error:
Failed to decode output: Error: overflow (operation="setValue",
fault="overflow", details="Number can only safely store up to 53
bits", version=4.0.32)
There is a known issue that require in view/pure functions don’t revert on public networks:
https://forum.openzeppelin.com/t/require-in-view-pure-functions-dont-revert-on-public-networks/1211
If you use Remix JavaScript VM then calling ViewLand with a non-existent id reverts as expected.
If you have questions on dapp development you can also ask in the OpenZeppelin Community Forum: https://forum.openzeppelin.com/
Disclosure: I am the Community Manager at OpenZeppelin

Example Oraclize files return 0: string: when called in Remix

I want to use Oraclize in Remix, to test it. I'm too stupid to use their examples.
How can I make this work?
From their Github I took the YouTube-Views code and copied it into Remix
pragma solidity >= 0.5.0 < 0.6.0;
import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";
contract YoutubeViews is usingOraclize {
string public viewsCount;
event LogYoutubeViewCount(string views);
event LogNewOraclizeQuery(string description);
constructor()
public
{
update(); // Update views on contract creation...
}
function __callback(
bytes32 _myid,
string memory _result
)
public
{
require(msg.sender == oraclize_cbAddress());
viewsCount = _result;
emit LogYoutubeViewCount(viewsCount);
// Do something with viewsCount, like tipping the author if viewsCount > X?
}
function update()
public
payable
{
emit LogNewOraclizeQuery("Oraclize query was sent, standing by for the answer...");
oraclize_query("URL", 'html(https://www.youtube.com/watch?v=9bZkp7q19f0).xpath(//*[contains(#class, "watch-view-count")]/text())');
}
}
When I use the viewCount it returns:
0: string:
This happens with all the other examples aswell.
With WolframAlpha eg. I also get the following error:
transact to WolframAlpha.update errored: VM error: revert.
revert The transaction has been reverted to the initial state.
Note: The constructor should be payable if you send value. Debug the transaction to get more information.
Ok you don't see the answer like a normal result in Remix:
You have to go under settings and open the Oraclize plug in.
If you then deploy the contract and or click update, you get the result shown in the plug in.

Trying to make an array with a variable size in solidity

I am trying to write string to the blockchain using events. This will cost a lot of gas regularly, so I am attempting to compress my strings. They become compressed into a uint8array in js. Here is my solidity script:
pragma solidity ^0.4.18;
contract EthProj {
event Message(uint8[] message, address add, uint256 cost);
event Username(uint8[] name, address add, uint256 cost);
function setMessage(uint8[] _fMessage) public {
uint8[] memory output = new uint8[](_fMessage.length);
output = _fMessage;
emit Message(output, msg.sender, gasleft());
}
function setUsername(uint8[] _userName) public {
emit Username(_userName, msg.sender, gasleft());
}
}
My goal with this is to have the size of the array be dependent on the size of the compressed text, but I get invalid number of arguments error when calling it using this:
message = document.getElementById("MessageBox").value;
compressed = shoco.compress(message);
EthProj.setMessage.sendTransaction(compressed, {from: document.getElementById("add").value});`
Can you not make an array with variable size, and if I can't, than how do I go about achieving my goal? The error is: Invalid number of arguments to solidity function