Skip to content

grohiro/meta-transaction

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Meta transaction

This repository implements generic version of meta transaction.

Meta transaction is proposed by uPort and detailed description can be found here

Below describes concept of meta transaction demonstrated in this repository.

concept

Prerequisite

Install docker for mac

Software versions

name version
solidity 0.4.17
solidity-compiler v0.4.19+commit.c4cbbb05

How to start server

$ sh script/start.sh

Setup account

Create config.json at root folder

{
  "server_account": {
    "privateKey": <PRIVATE KEY>,
    "address": <ADDRESS>,
  },
  "client_account": {
    "privateKey": <PRIVATE KEY>,
    "address": <ADDRESS>,
  }
}

Compile

$ sh script/compile.sh

Test

$ sh script/enter.sh
# npm run test

Usage

Client

let rawTx = await MetaTransactionClient.createTx(targetAbi, targetFunctionName, args, {
  to: targetAddress,
  value: 0,
  nonce: 0, // nonce must match the one at TxRelay contract
  gas: 2000000,
  gasPrice: 2000000,
  gasLimit: 2000000
});

// result txToServer object should be send to app server
txToServer = await MetaTransactionClient.createRawTxToRelay(
  rawTx,
  clientAccountAddress,
  clientAccountPrivateKey,
  txRelayContractAddress
);

Server

// sign tx with account which has some ether.
let signedTxToRelay = await MetaTransactionServer.createRawTxToRelay(
  JSON.parse(txRelayContractAbi),
  txToServer.sig, // from client
  txToServer.to, // from client
  txToServer.from, // from client
  txToServer.data, // from client
  {
    "gas": 2000000,
    "gasPrice": 2000000,
    "gasLimit": 2000000,
    "value": 0,
    "to": txRelayContractAddress,
    "nonce": 0, // nonce of address which signs tx ad server
    "from": serverAccountAddress
  },
  serverAccountPrivateKey
);

// esnd tx to TxRelay contract
const result = await web3.eth.sendSignedTransaction('0x' + signedTxToRelay);

About

Ethereum meta-transaction concept

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • JavaScript 94.8%
  • Shell 4.2%
  • Dockerfile 1.0%