added set instance and build DSA

This commit is contained in:
Sowmay Jain 2020-04-07 05:56:09 +10:00
parent b74f9cf62b
commit 97feda319d

View File

@ -1,7 +1,12 @@
# Developing on DSA # Developing on DSA
We empower third-party developers to build dapps, use-cases, and other integrations on DSAs platform. That way, users can get curated experience as per their needs, and developers can build their own businesses supporting those users. This virtuous circle creates new opportunities and benefits users, developers, and protocols. We empower third-party developers to build dapps, use-cases, and other integrations on DSAs platform. That way, users can get curated experience as per their needs, and developers can build their own businesses supporting those users. This virtuous circle creates new opportunities and benefits users, developers, and protocols.
Our SDK abstract all the complex internal (like handling addresses, ABIs etc) and provide developers with a simple interface to interact with DSA platform. ## Index
* [Get Started](#get-started)
* Get Accounts
* Set Instance
* Build DSA
* Cast Spell
## Get Started ## Get Started
@ -32,12 +37,13 @@ if (window.ethereum) {
} }
``` ```
## Get Accounts ## Get Accounts
Once connected to a web3 client, get all the DSA where a specific address is authorised: Once connected to a web3 client, get all the DSA where a specific address is authorised.
```js ```js
const accounts = await web3.eth.getAccounts() let accounts = await web3.eth.getAccounts()
dsa.getAccounts(accounts[0]) dsa.getAccounts(accounts[0])
.then(data => { .then(data => {
return data return data
@ -51,7 +57,7 @@ dsa.getAccounts(accounts[0])
`address` - An ethereum address. `address` - An ethereum address.
### Returns ### Returns
An `Array` of `Object` of all the DSA where `address` is authorised. `Array` of `Object` with all the DSA where `address` parameter is authorised.
```js ```js
[ [
@ -64,12 +70,12 @@ An `Array` of `Object` of all the DSA where `address` is authorised.
] ]
``` ```
Web3 equivalent of the above: Web3 equivalent of the above (return value might have different format):
```js ```js
const ABI = [{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"origin","type":"address"}],"name":"LogAccountCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_newAccount","type":"address"},{"indexed":true,"internalType":"address","name":"_connectors","type":"address"},{"indexed":true,"internalType":"address","name":"_check","type":"address"}],"name":"LogNewAccount","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"accountVersion","type":"uint256"},{"indexed":true,"internalType":"address","name":"check","type":"address"}],"name":"LogNewCheck","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"master","type":"address"}],"name":"LogNewMaster","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"master","type":"address"}],"name":"LogUpdateMaster","type":"event"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"account","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_newAccount","type":"address"},{"internalType":"address","name":"_connectors","type":"address"},{"internalType":"address","name":"_check","type":"address"}],"name":"addNewAccount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"uint256","name":"accountVersion","type":"uint256"},{"internalType":"address","name":"_origin","type":"address"}],"name":"build","outputs":[{"internalType":"address","name":"_account","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"uint256","name":"accountVersion","type":"uint256"},{"internalType":"address[]","name":"_targets","type":"address[]"},{"internalType":"bytes[]","name":"_datas","type":"bytes[]"},{"internalType":"address","name":"_origin","type":"address"}],"name":"buildWithCast","outputs":[{"internalType":"address","name":"_account","type":"address"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"accountVersion","type":"uint256"},{"internalType":"address","name":"_newCheck","type":"address"}],"name":"changeCheck","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newMaster","type":"address"}],"name":"changeMaster","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"check","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"connectors","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"version","type":"uint256"},{"internalType":"address","name":"query","type":"address"}],"name":"isClone","outputs":[{"internalType":"bool","name":"result","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"list","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"master","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_master","type":"address"},{"internalType":"address","name":"_list","type":"address"},{"internalType":"address","name":"_account","type":"address"},{"internalType":"address","name":"_connectors","type":"address"}],"name":"setBasics","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"updateMaster","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"versionCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}] let ABI = [link](https://github.com/InstaDApp/dsa-sdk/blob/master/src/abi/resolvers/core.json)
const address = "0xD6fB4fd8b595d0A1dE727C35fe6F1D4aE5B60F51" let contract = "0xD6fB4fd8b595d0A1dE727C35fe6F1D4aE5B60F51"
const accounts = await web3.eth.getAccounts() let accounts = await web3.eth.getAccounts()
new web3.eth.Contract(ABI, address); new web3.eth.Contract(ABI, contract);
.getOwnerDetails(accounts[0]) .getOwnerDetails(accounts[0])
.call({ from: "0x..." }) .call({ from: "0x..." })
.then((data) => { .then((data) => {
@ -80,4 +86,72 @@ new web3.eth.Contract(ABI, address);
}); });
``` ```
## Set Instance
(Optional) Once you get the DSA(s), set some common values so you don't have to pass similar arguments in further calls.
```js
let accounts = await web3.eth.getAccounts();
let dsaAccount = dsa.getAccounts(accounts[0])
dsa.setInstance({
id: dsaAccount[0].id,
account: dsaAccount[0].account,
origin: "0x..." // optional
})
```
### Parameters
1. `Object`
* `id` - `Number`: The number of DSA.
* `account` - `String`: The address of DSA.
* `origin` - `String`: The address to track the transaction origination (affiliates).
## Build DSA
Build a new DSA.
```js
dsa.build()
.then(data => {
return data
})
.catch(error => {
return error
})
```
### Parameters
1. `Object` (ALL optional)
* `owner`: The authorised address which will be authorised on DSA (defaulted to selected address).
* `origin` - `String`: The address to track the transaction origination (affiliates).
* `from` - `String`: The address transactions should be made from (defaulted to selected address).
* `gasPrice` - `String`: The gas price in wei to use for transactions.
* `gas` - `Number`: The maximum gas provided for a transaction (gas limit).
### Returns
`String`: Transaction hash `0x.....`.
Web3 equivalent of the above (return value might have different format):
```js
let ABI = [link](https://github.com/InstaDApp/dsa-sdk/blob/master/src/abi/core/index.json)
let contract = "0xD6fB4fd8b595d0A1dE727C35fe6F1D4aE5B60F51"
let accounts = await web3.eth.getAccounts()
let owner = "0x..."
let version = 1;
let origin = "0x..."
new web3.eth.Contract(ABI, contract).methods
.build(owner, version, origin)
.send({
from: accounts[0]
})
.on("transactionHash", (txHash) => {
resolve(txHash);
})
.on("error", (err) => {
reject(err);
});
```
Our team is super active to assist you with all of your queries at our [TG developer group](https://t.me/instadevelopers) or [discord channel](https://discord.gg/83vvrnY). Our team is super active to assist you with all of your queries at our [TG developer group](https://t.me/instadevelopers) or [discord channel](https://discord.gg/83vvrnY).