Main Net
- Submit a request to index the OmiseGo ERC20 token contract.
- Find it in the API
Martin Allen & Kristoffer Josefsson, FOAM
May 27, 2018
Turns out over 12 million dollars!
uint48
ABI
contract GreedyStorage is owned {
uint public m; // automatically generate "getter" m()
event Overidden(address overrider)
function increase (uint n) onlyOwner returns (uint) {
m = m + n;
return m;
}
function override (uint n) payable {
require(msg.value > 100000); // this is the price
m = n;
Overidden(msg.sender);
}
}
The selector is how we speficy the function to execute
selector :: FunctionSignature -> ByteString
selector = take 8 $ sha3
> selector "increase(uint256)"
> "30f3f0db"
so for GreedyStorage
we get
Subtle changes leading to broken application code
Contract
moduleBigNumber
newtype Vector n a = Vector (Array a)
nilVector :: forall a . Vector Z a
nilVector = Vector mempty
vCons :: forall a n . a
-> Vector n a
-> Vector (S n) a
vCons a (Vector as) = Vector (a : as)
infixr 6 vCons as :<
toVector :: forall a n . KnownNat n
=> Array a
-> Maybe (Vector n a)
toVector as = if natVal (Proxy :: Proxy n) /= A.length as
then Nothing
else Just (Vector as)
bools :: Vector N3 Boolean
bools = true :< false :< true :< nilVector
data Tuple0 = Tuple0
newtype Tuple1 a = Tuple1 a
...
data Tuple16 a b c d e f g h i j k l m n o p =
Tuple16 a b c d e f g h i j k l m n o p
purescript-web3
didn’t handle these well.class ABIEncode a where
toDataBuilder :: a -> HexString
class ABIDecode a where
fromDataParser :: Parser String a
instance abiEncodeUint :: IntSize n => ABIEncode (UIntN n) where
toDataBuilder a = uInt256HexBuilder <<< unUIntN $ a
instance abiDecodeUint :: IntSize n => ABIDecode (UIntN n) where
fromDataParser = do
a <- uInt256HexParser
maybe (fail $ msg a) pure <<< uIntNFromBigNumber $ a
where
msg n = let size = sizeVal (Proxy :: Proxy n)
in "Couldn't parse as uint" <> show size <> ":" <> show n
Type
) admit a generic decompositionABIEncode
hs-web3
implementation.You will be able to use purescript-web3
without knowing how it works. This means:
Simple Storage allows us to change a uint256
, query that state, and listen for updates to that state.
Here is the client library generated which is generated from the ABI 1
npm build
step - any breaking changes to your contracts will cause compile time errors in your application.sendTx
method:class TxMethod (selector :: Symbol) a where
sendTx :: forall p e u.
IsAsyncProvider p
=> IsSymbol selector
=> EtherUnit u
=> Maybe Address -- Contract address
-> Address -- From address
-> u -- paymentValue
-> Tagged (SProxy selector) a -- Method data
-> Web3 p e HexString -- 'Web3' wrapped tx hash
call
methods are similar, but with a return typeevent
method, which similarly defined in hs-web3
event :: forall p e a i ni. IsAsyncProvider p
=> DecodeEvent i ni a
=> EventFilter a
=> Address
-> (a -> ReaderT Change (Web3 p e) EventAction)
-> Web3 p e (Fiber (eth :: ETH | e) Unit)
CountSet
event, updating the React component’s state.ContinueEvent
, this poll never terminates.monitorCount :: R.ComponentDidMount CountStateProps CountState (eth :: ETH | eff)
monitorCount this = void $ do
props <- R.getProps this
launchAff do
void $ runWeb3 metamask $
event config.simpleStorageAddress $ \(SimpleStorage.CountSet cs) -> do
_ <- liftEff <<< R.transformState this $ _{currentCount= show cs._count}
pure ContinueEvent
There are a few other boiler plate type declarations that are generated, but this is pretty much it.↩