Skip to content

Commit

Permalink
send request and wallet connect (#3)
Browse files Browse the repository at this point in the history
* send request and wallet connect

* update readme and dev

* finish specs and wallet connect implementation
  • Loading branch information
spape authored Sep 24, 2021
1 parent eb7629e commit b386607
Show file tree
Hide file tree
Showing 15 changed files with 53,421 additions and 286 deletions.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,55 @@ let wallet = getWallet()
await wallet.switchTo('bsc')
```

### sendTransaction

Sign and send a transaction through the connected wallet:

```javascript

let wallet = getWallet()

let sentTransaction = await wallet.sendTransaction({
blockchain: 'ethereum',
to: '0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92',
api: [{"inputs":[{"internalType":"address","name":"_configuration","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ETH","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"configuration","outputs":[{"internalType":"contract DePayRouterV1Configuration","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"pluginAddress","type":"address"}],"name":"isApproved","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"path","type":"address[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"address[]","name":"addresses","type":"address[]"},{"internalType":"address[]","name":"plugins","type":"address[]"},{"internalType":"string[]","name":"data","type":"string[]"}],"name":"route","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}],
method: 'route',
params: {
path: ["0xb056c38f6b7Dc4064367403E26424CD2c60655e1","0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2","0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb"],
amounts: ["11275067000000000000000","100000000000000000000", "1632063302"],
addresses: ["0x39794c3171d4D82eB9C6FBb764749Eb7ED92881d", "0x39794c3171d4D82eB9C6FBb764749Eb7ED92881d"],
plugins: ["0xe04b08Dfc6CaA0F4Ec523a3Ae283Ece7efE00019", "0x99F3F4685a7178F26EB4F4Ca8B75a1724F1577B9"],
data: []
},
value: "0"
})

```

or a simple value transfer:

```javascript

let wallet = getWallet()

let sentTransaction = await wallet.sendTransaction({
blockchain: 'ethereum',
to: '0xae60aC8e69414C2Dc362D0e6a03af643d1D85b92',
value: "1000000000000000"
})

```

#### Wrong network

`sendTransaction` rejects with:

```javascript
{ code: 'WRONG_NETWORK' }
```

in case wallet is connected to the wrong network and network cant be switched automatically.

## Development

### Get started
Expand Down
10 changes: 9 additions & 1 deletion dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ <h1>Wallet Debug</h1>
<div class="col">
<h1>WalletConnect connect</h1>
<p>Test wallet connect</p>
<button class='btn btn-primary' onClick='Web3Wallets.supported[0].connect()'>Test it</button>
<button class='btn btn-primary' onClick='Web3Wallets.wallets.WalletConnect.connect()'>Test it</button>
</div>
</div>

<div class="row pt-5">
<div class="col">
<h1>Send transaction</h1>
<p></p>
<button class='btn btn-primary' onClick='Web3Wallets.getWallet().sendTransaction({ transaction: { blockchain: "ethereum", to: "0x08B277154218CCF3380CAE48d630DA13462E3950", value: "1000000000000000" } })'>Test it</button>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit b386607

Please sign in to comment.