-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from leapdao/feat/v1
feat: allow to sendTransaction and get TransactionReceipt
- Loading branch information
Showing
5 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,47 @@ | ||
# leap-provider | ||
# leap-provider | ||
|
||
Ethers.js provider to work with Leap Network. | ||
|
||
## Install | ||
|
||
```sh | ||
yarn add leap-provider | ||
``` | ||
|
||
## Usage | ||
|
||
Connect to a Wallet: | ||
|
||
```js | ||
const LeapProvider = require('leap-provider'); | ||
const provider = new LeapProvider('https://testnet-node.leapdao.org'); | ||
|
||
// can be passed in a Wallet | ||
const plasmaWallet = new ethers.Wallet(privKey, provider); | ||
|
||
// or connected to existing wallet | ||
const otherWallet = Wallet.createRandom(); | ||
otherWallet.connect(provider); | ||
``` | ||
|
||
Send transaction to Leap Network: | ||
|
||
```js | ||
const LeapProvider = require('leap-provider'); | ||
const provider = new LeapProvider('https://testnet-node.leapdao.org'); | ||
|
||
// create some LeapTransaction | ||
const tx = Tx.transfer( | ||
... | ||
); | ||
|
||
// tx should be signed | ||
tx.signAll(wallet.privateKey); | ||
|
||
// send via provider | ||
const resp = await wallet.provider.sendTransaction(tx); | ||
|
||
// wait for inclusion, you will get a proper TransactionReceipt once tx is included in a block | ||
const receipt = await resp.wait(); | ||
console.log(receipt); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const ethers = require('ethers'); | ||
|
||
class LeapProvider extends ethers.providers.JsonRpcProvider { | ||
|
||
/** | ||
* Overrides `BaseProvider.sendTransaction` to exclude tx parsing | ||
* and resolveProperties. | ||
* | ||
* Given signedTransaction is non-standard, it is a LeapTransaction | ||
* as defined in leap-core, so we cannot parse. | ||
* We don't need resolveProperties as LeapTransaction cannot | ||
* have property promise. | ||
* | ||
* See: https://github.com/ethers-io/ethers.js/blob/7075c8c2352ec306b5679da6fbe7c2ddf7bd65d1/src.ts/providers/base-provider.ts#L873 | ||
* @param {LeapTransaction} signedTransaction signed tx | ||
*/ | ||
sendTransaction(signedTransaction) { | ||
return this.ready.then(() => { | ||
let params = { signedTransaction: signedTransaction.hex() }; | ||
return this.perform('sendTransaction', params).then((hash) => { | ||
return this._wrapTransaction({ hash: signedTransaction.hash() }, hash); | ||
}, (error) => { | ||
error.transaction = { raw: signedTransaction.hex() }; | ||
error.transactionHash = signedTransaction.hash(); | ||
throw error; | ||
}); | ||
}); | ||
} | ||
|
||
} | ||
|
||
module.exports = LeapProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "leap-provider", | ||
"version": "1.0.0", | ||
"description": "Ethers.js Provider for Leap Network", | ||
"main": "index.js", | ||
"repository": "git@github.com:leapdao/leap-provider.git", | ||
"author": "Kosta Korenkov <kosta@whoot.me>", | ||
"license": "MIT", | ||
"peerDependencies": { | ||
"ethers": "~4.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|