FIX docs for new functions

pull/1/head
pubkey 7 years ago
parent 7701369652
commit 0088326e6c
  1. 63
      README.md
  2. 2
      src/tx-data-by-compiled.js
  3. 16
      test/tutorials.test.js
  4. 12
      tutorials/signed-data.md
  5. 3
      typings/index.d.ts

@ -6,15 +6,12 @@ Cryptographic javascript-functions for ethereum and how to use them together wit
### Creating Keys and use them for ethereum-transactions
In this tutorial we will create an ethereum-identity and use it so send transactions to the blockchain.
[Creating transactions](./tutorials/creating-transactions.md).
In this tutorial we will create an ethereum-identity and use it so send transactions to the blockchain. [Creating transactions](./tutorials/creating-transactions.md).
### Sign and validate data with solidity
### Sending encrypted and signed data to other identites
## Functions
### Install
@ -133,3 +130,61 @@ Decrypts the encrypted data with the privateKey. Returns (async) the message as
);
// 'foobar'
```
### signTransaction()
Signs a raw transaction with the privateKey. Returns a serialized tx which can be submitted to the node.
```javascript
const ident = EthCrypto.createIdentity();
const rawTx = {
from: identity.address,
to: '0x86Fa049857E0209aa7D9e616F7eb3b3B78ECfdb0',
value: 1000000000000000000,
gasPrice: 5000000000,
nonce: 0,
gasLimit: 21000
};
const signedTx = EthCrypto.signTransaction(
rawTx,
identity.privateKey
);
console.log(signedTx);
// > '071d3a2040a2d2cb...'
// you can now send the tx to the node
const receipt = await web3.eth.sendSignedTransaction(signedTx);
```
### txDataByCompiled()
Creates the data-string which must be submitted with an transaction to create a contract-instance.
```javascript
const solc = require('solc');
// create compiled solidity-code
const compiled = solc.compile(
'contract ExampleContract {...',
1
).contracts[':ExampleContract'];
const createCode = EthCrypto.txDataByCompiled(
compiled.interface, // abi
compiled.bytecode, // bytecode
[identity.address] // constructor-arguments
);
// now you can submit this to the blockchain
const serializedTx = EthCrypto.signTransaction(
{
from: identity.address,
nonce: 0,
gasLimit: 5000000,
gasPrice: 5000000000,
data: createCode
},
identity.privateKey
);
const receipt = await web3.eth.sendSignedTransaction(serializedTx);
```

@ -2,7 +2,7 @@ import {
web3
} from './util';
export function txDataByCompiled(
export default function txDataByCompiled(
abi,
bytecode,
args

@ -38,19 +38,11 @@ describe('tutorials.test.js', () => {
// compile the code into an object
const compiled = solc.compile(contractCode, 1).contracts[':DonationBag'];
// create contract-create-code
const web3Contract = new web3.eth.Contract(
JSON.parse(compiled.interface),
null, {
data: '0x' + compiled.bytecode
}
const createCode = EthCrypto.txDataByCompiled(
compiled.interface, // abi
compiled.bytecode, // bytecode
[creatorIdentity.address] // constructor-arguments
);
console.log('compiled.bytecode: ' + compiled.bytecode);
const createCode = web3Contract.deploy({
arguments: [creatorIdentity.address]
}).encodeABI();
console.log('createCode: ' + createCode);
// create create-tx
const rawTx = {

@ -76,13 +76,11 @@ Now that we have the bytecode of the contract, we can submit a transaction to cr
```javascript
// create contract-create-code
const web3Contract = new web3.eth.Contract(JSON.parse(compiled.interface), null, {
data: '0x' + compiled.bytecode
});
const createCode = web3Contract.deploy({
arguments: [creatorIdentity.address] // this is the address in the DonationBag-constructor
}).encodeABI();
const createCode = EthCrypto.txDataByCompiled(
compiled.interface, // abi
compiled.bytecode, // bytecode
[creatorIdentity.address] // constructor-arguments
);
// create a transaction the deploys the contract
const rawTx = {

@ -64,11 +64,8 @@ export type util = {
web3: Web3
};
export function publicKeyToAddress(publicKey: string): string;
declare const _default: {
addressByPublicKey,
createIdentity,

Loading…
Cancel
Save