ethereum samples

API | Resources These resources and examples are provided for informational purposes in the hope that they will be useful. if you have any questions or suggestions.We provide a working example using RunKeeper data here.You may also be interested in EtherOpt, a state-of-the-art open source decentralized options exchange powered by Reality Keys.Their source code is available on GitHub.On Ethereum you will usually want to use signed data rather than published yes/no keys.The data you need is contained in the "signature_v2" fields returned by the API.You can ignore fields not discussed here.Until the fact is settled, the signed_value and sig_r, sig_s and sig_v fields will be null.When you set up a transaction, specify the following: fact_hash: The hash that uniquely identifies the fact we are reporting on.ethereum_address: The address that will be used to sign the completed data.base_unit: A number by which final numerical results will be multipled before signing.This is done to avoid needing to process decimals / floating points, which are particularly troublesome in Solidity.

For numerical data we standardize on a base_unit of 1000000000000000000, which is also the number of Wei in an Eth.For true/false data we use a base_unit of 1 and always sign 1 or 0.When the parties use the data to settle a transaction, the contract will use the same data again, plus the value (signed_value), which is hex-encoded and padded to 32 bytes, and the three parts of the signature, v, r and s.The data is verified as follows: Combine the event hash and the result: Recreate the ethereum_address from the signature.This will return a value even if the signature is wrong, so check it's the right address!You can now safely settle your contract based on the signed_value.If you don't need anything beyond the decimal point you can divide by base_unit and forget about it.Some of the patterns below are used in our realitykeysdemo.py sample script.A traditional multi-signature transaction in Bitcoin looks like this: 2 A-pub B-pub 2 OP_CHECKMULTISIG To spend this transaction you would need to create a signature script with private keys corresponding to both A-pub and B-pub, eg: 0 A-sig B-sig The bitcoin script interpreter prepends the data provided in the signature script to create: 0 A-sig B-sig 2 A-pub B-pub 2 OP_CHECKMULTISIG The above will evaluate to true if the signatures are correct, unlocking the funds.

This is normally done using P2SH.When using Reality Keys you often want to lock up some funds and have them released to one person in one case, and the other person in the other case.This can be done in a single transaction with two branches: Alice + Yes Bob + No Branching transactions can be accomplished using OP_IF, eg: OP_IF 2 A-pub Yes-pub 2 OP_CHECKMULTISIG OP_ELSE 2 B-pub No-pub 2 OP_CHECKMULTISIG OP_ENDIF When you provide a signature to spend money locked up with this script, you will need to add an additional flag to indicate the appropriate branch.
oil contractors bitcoinThis can then be signed with either: 0 A-sig Yes-sig 1 < flag directs OP_IF to the first branch or 0 B-sig No-sig 0 < flag directs OP_IF to the second branch The above is implemented in the realitykeysdemo.py sample script.
ethereum aud exchange

Additionally, you may want a third branch giving the parties the option to release the funds early without waiting for the Reality Keys: Bob + Alice This can be accomplished using nested OP_IFs, eg: OP_IF OP_IF 2 A-pub Yes-pub 2 OP_CHECKMULTISIG OP_ELSE 2 B-pub No-pub 2 OP_CHECKMULTISIG OP_ENDIF OP_ELSE 2 A-pub B-pub 2 OP_CHECKMULTISIG OP_ENDIF The above pattern is implemented in the bymycoins JavaScript demo app.
litecoin cpu onlyIt is possible to combine ECC keys to do the equivalent to the above in a simple multi-sig transaction which is more likely to be supported by Bitcoin wallets.
bitcoin vorteile nachteile1 (A-pub+Yes-pub) (B-pub+No-pub) 2 OP_CHECKMULTISIG However, this approach is somewhat unorthodox, and from a security perspective we prefer to avoid novel or interesting cryptographic protocols where practical.
ethereum price ticker

We therefore recommend the branching transaction suggested above if it meets your needs.One specific concern is that if she knows the Reality Keys public keys in advance, Alice could produce a special public key which subtracted the Reality Keys public key, resulting in a public key she was able to sign without knowing the Reality Key.It should be possible to defeat this by either: Ensuring that the users' exchange of public keys takes place before the Reality Keys are published.
bitcoin senate hearing video(Not recommended) Having each party prove that they know the private key corresponding to their own public key, for example by signing a message or making a payment from it.The realitykeysdemo.py tool can be instructed to use this method by invoking it with the --ecc-voodoo flag.As our keys are published publicly, anyone who can see your transaction once it has been redeemed would normally be able to tell which fact the transaction represented.

If you wish to avoid this, you can use similar ECC key combination techniques, similar to Stealth Addresses, to make the keys unrecognizable to anyone except the parties to the transction.For example, parties to the transaction can agree on an arbitrary private key and combine that with each Reality Key using ECC addition.The steps usually used in Stealth Addresses are as follows: Each party starts with their own public key.Parties create a shared secret by multiplying the other party's public key with their own private key.(In this case alternative methods of agreeing a shared secret would also work.)Parties hash the resulting shared secret to create a private key.Create a public key from the hashed shared secret.Combine the public key with the public key you wish to make unidentifiable.To spend the funds sent to the Stealth Address, the hashed shared secret is combined with the private key of the key you had been making identifiable, producing a private key that can be used to spend the funds.

Often people want to make conditional transactions as described above to be funded by multiple parties, and have them only come into force once all parties have funded them.In bitcoin this can be accomplished by creating a single transaction spending the total funds, and having each party check it, add their own funds to it and sign it.The transaction is not valid until it has been funded with as much money as it will spend.If the person who creates the transaction does not yet know which particular coins the other parties will be using to fund it, they can sign it using the SIGHASH_ANYONECANPAY flag.This indicates that they do not care what additional inputs are added to the transaction, as long as it fully funds the outputs.For example: Alice and Bob agree a contract, including how much should be put in by each person, under what conditions it will pay Alice and under what conditions it will pay Bob.Either Alice or Bob registers the event with Reality Keys, and shares the resulting ID with the other.

Alice and Bob exchange public keys.Alice creates a transaction with the agreed outputs and her own inputs, and signs it and sends it to Bob.(It isn't yet valid, because the inputs aren't sufficient to fund the outputs.)Bob checks that the outputs are what he expects, adds his own inputs and broadcasts it to the network.In realitykeysdemo.py we take a different approach: Before funding the contract transaction, each party pays their stake into an address controlled solely by the public key they will be using for the transaction.Since both parties know the other party's public key, they are able to check the blockchain and find the relevant inputs that should be used for the contract transaction.Knowing all the inputs that should be in the transaction, they can create the transaction completely without needing to use SIGHASH_ANYONECANPAY.This also has the effect of requiring the parties to spend from their own public keys before any money is locked up in the contract transaction, which proves that they have the private key to the public key they have exchanged, which is recommended if using ECC addition to create a standard transaction.