koris-accessor v0.0.27
KorisAccessor
KorisAccessor is a frontend library that allows you to access the smart contracts of the Koris App. With a specified backend apiUrl, KorisAccessor can send transactions to Koris smart contracts and decide to use gasless way according to backend settings.
Installation
npm install koris-accessor
Usage
Creating a KorisAccessor instance
To create a new instance of KorisAccessor, you need to provide the following parameters:
chainId
: The ID of the blockchain network you want to connect to.apiUrl
: The URL of the backend API that provides access to the smart contracts.signerOrProvider
: An optional parameter that allows you to specify a signer or provider for the transactions.
import { KorisAccessor } from "koris-accessor";
const blockchain = await KorisAccessor.create({
chainId: 599,
apiUrl: "https://api-gw.dev.koris.io/api/v2",
signerOrProvider: provider.getSigner(),
});
Accessing Smart Contracts
Once you have created a KorisAccessor instance, you can access the smart contracts using the contracts
property.
const dac = blockchain.contracts.DAC(dacAddress);
You can access the following smart contracts:
Configuration
DACFactory
DAC
DACHelper
EcoNode
Forwarder
PermitManager
ProposalFactory
RP
SimpleProposal
Sending Transactions
You can send transactions by calling the functions of the smart contracts.
const tx = await dac.join(0, []);
Gasless Transactions
KorisAccessor can decide to use gasless way according to backend settings. If gasless is enabled, the transaction will be sent without requiring the user to pay gas fees.
Full Example
import { KorisAccessor } from "koris-accessor";
async function join(blockchain: KorisAccessor, dacAddress: string) {
console.log("join dac", dacAddress);
const dac = blockchain.contracts.DAC(dacAddress);
const tx = await dac.join(0, []);
console.log("sent tx:", tx);
const receipt = await tx.wait();
console.log("receipt=", receipt);
return tx.hash;
}
async function quit(blockchain: KorisAccessor, dacAddress: string) {
console.log("quit dac", dacAddress);
const dac = blockchain.contracts.DAC(dacAddress);
const tx = await dac.quit();
console.log("sent tx:", tx);
const receipt = await tx.wait();
console.log("receipt=", receipt);
return tx.hash;
}
async function fetchBlockchainData() {
//@ts-ignore
const provider = new ethers.providers.Web3Provider(window.ethereum);
await provider.send("eth_requestAccounts", []);
console.log("create KorisAccessor");
const blockchain = await KorisAccessor.create({
chainId: 599,
apiUrl: "https://api-gw.dev.koris.io/api/v2",
signerOrProvider: provider.getSigner(),
});
return blockchain;
}
function App() {
const [blockchain, setBlockchain] = useState(null);
useEffect(() => {
async function fetchData() {
const blockchainData = await fetchBlockchainData();
setBlockchain(blockchainData);
}
fetchData();
}, []);
if (!blockchain) {
return <div>Loading...</div>;
}
return (
<div className="App">
<DemoForm blockchain={blockchain} />
</div>
);
}
class DemoForm extends React.Component<{ blockchain: KorisAccessor }> {
state = {
dacAddress: "",
tx: "-",
};
render() {
return (
<div>
DAC:
<input
placeholder="dac address here"
value={this.state.dacAddress}
onChange={(evt) => this.updateInputValue(evt)}
/>
<button
onClick={async () =>
this.setState({
tx: await join(this.props.blockchain, this.state.dacAddress),
})
}
>
Join
</button>
<button
onClick={async () =>
this.setState({
tx: await quit(this.props.blockchain, this.state.dacAddress),
})
}
>
Quit
</button>
<div>tx: {this.state.tx}</div>
</div>
);
}
updateInputValue(evt) {
console.log("this.state.dacAddress=", this.state.dacAddress, "evt=", evt);
this.setState({ dacAddress: evt.target.value });
}
}
API Reference
KorisAccessor
create({ chainId, apiUrl, signerOrProvider }): Promise<KorisAccessor>
Creates a new instance of KorisAccessor with the specified parameters.
chainId
: The ID of the blockchain network you want to connect to.apiUrl
: The URL of the backend API that provides access to the smart contracts.signerOrProvider
: An optional parameter that allows you to specify a signer or provider for the transactions.
Returns a Promise that resolves with a new instance of KorisAccessor.
Contracts
Configuration(signerOrProvider?: Signer | Provider)
Returns an instance of the Configuration
smart contract.
signerOrProvider
: An optional parameter that allows you to specify a signer or provider for the transactions.
Returns an instance of the Configuration
smart contract.
DACFactory(signerOrProvider?: Signer | Provider)
Returns an instance of the DACFactory
smart contract.
signerOrProvider
: An optional parameter that allows you to specify a signer or provider for the transactions.
Returns an instance of the DACFactory
smart contract.
DAC(dacAddress: string, signerOrProvider?: Signer | Provider)
Returns an instance of the DAC
smart contract with the specified address.
dacAddress
: The address of theDAC
smart contract.signerOrProvider
: An optional parameter that allows you to specify a signer or provider for the transactions.
Returns an instance of the DAC
smart contract.
DACHelper(signerOrProvider?: Signer | Provider)
Returns an instance of the DACHelper
smart contract.
signerOrProvider
: An optional parameter that allows you to specify a signer or provider for the transactions.
Returns an instance of the DACHelper
smart contract.
EcoNode(signerOrProvider?: Signer | Provider)
Returns an instance of the EcoNode
smart contract.
signerOrProvider
: An optional parameter that allows you to specify a signer or provider for the transactions.
Returns an instance of the EcoNode
smart contract.
Forwarder(signerOrProvider?: Signer | Provider)
Returns an instance of the Forwarder
smart contract.
signerOrProvider
: An optional parameter that allows you to specify a signer or provider for the transactions.
Returns an instance of the Forwarder
smart contract.
PermitManager(signerOrProvider?: Signer | Provider)
Returns an instance of the PermitManager
smart contract.
signerOrProvider
: An optional parameter that allows you to specify a signer or provider for the transactions.
Returns an instance of the PermitManager
smart contract.
ProposalFactory(signerOrProvider?: Signer | Provider)
Returns an instance of the ProposalFactory
smart contract.
signerOrProvider
: An optional parameter that allows you to specify a signer or provider for the transactions.
Returns an instance of the ProposalFactory
smart contract.
RP(signerOrProvider?: Signer | Provider)
Returns an instance of the RP
smart contract.
signerOrProvider
: An optional parameter that allows you to specify a signer or provider for the transactions.
Returns an instance of the RP
smart contract.
SimpleProposal(proposalAddress: string, signerOrProvider?: Signer | Provider)
Returns an instance of the SimpleProposal
smart contract with the specified address.
proposalAddress
: The address of theSimpleProposal
smart contract.signerOrProvider
: An optional parameter that allows you to specify a signer or provider for the transactions.
Returns an instance of the SimpleProposal
smart contract.
Conclusion
KorisAccessor is a powerful library that allows you to easily interact with the smart contracts of the Koris App. With its simple API and support for gasless transactions, it is an ideal choice for building decentralized applications on the Koris network.
10 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
11 months ago
11 months ago
11 months ago
11 months ago
10 months ago
12 months ago
9 months ago
11 months ago
9 months ago
11 months ago
12 months ago
12 months ago
12 months ago
12 months ago
1 year ago
1 year ago