How to generate a random number in solidity?

Solidity contracts are deterministic. Anyone who figures out how your contract produces randomness can anticipate its results and use this information to exploit your application. One option is to produce randomness off-chain (where it cannot be predicted) and use it in your smart contract. Chainlink VRF is an easy-to-implement solution for using random data in … Read more

How can I return an array of struct in solidity?

As you mentioned, this is not yet supported in Solidity. The powers that be are planning on changing it so you can, but for now, you have to retrieve the number of elements and then retrieve the decomposed struct as a tuple. function getBidCount(bytes32 name) public constant returns (uint) { return highestBidder[name].length; } function getBid(bytes32 … Read more

How to send an ERC20 token with web3js

Take EOS token transfering as the example. Below code need web3 and ethereumjs-tx. If you’ve not install them, install them with npm install web3 ethereumjs-tx var Tx = require(‘ethereumjs-tx’); var Web3 = require(‘web3’) var web3 = new Web3(new Web3.providers.HttpProvider(‘http://127.0.0.1:8545/’)) // set token source, destination and amount var myAddress = “0xaa597b7e8aaffe9f2a187bedb472ef3455957560” var toAddress = “0xa013927bffe9e879134061b9330a01884a65497c” var … Read more