zbyte-relay-client
v1.1.8
Published
light weight client library to interact with the relay server
Downloads
3
Readme
Relay Client
The Relay Client provides functionalities to establish connections with the relay server, enabling operations such as smart contract deployment and invocation. Additionally, it facilitates interaction with wallets to sign transactions necessary for executing these operations.
Installation
To install the library, execute the following npm command:
npm install @zbyteio/zbyte-relay-client
Usage
Refer to the code snippet below for integrating the client library into your project:
// define relay configuration
const relayConfig = {
relayBaseURL: <relay server base url>, // URL for the relay service
nativeChainId: <chain id>, // Chain ID for the native blockchain (137 for mainnet, 80002 for testnet)
pollWait: <poll wait time in milliseconds>, // Wait time between subsequent polling calls for operation status
pollTimeOut: <poll time out in milliseconds>, // Timeout duration for ceasing waiting on an operation
};
// create wallet interface
const wallet: IzbyteWallet // Wallet of type IzbyteWallet (refer to https://github.com/orgs/Zbyteio/packages/npm/package/zbyte-wallet-ui-sdk)
const relayClient = new RelayClient(relayConfig, wallet); // Wallet is of type IzbyteWallet as specified in interfaces
// Deploy a smart contract on a blockchain
relayClient.deployContract(
<bytecode>, // Bytecode of the smart contract
<contract abi>, // ABI of the smart contract
<[contructor args]>, // Constructor arguments
<chain id> // Chain ID of the blockchain for contract deployment
);
// returns the transaction receipt type (refer to https://docs.ethers.org/v5/api/providers/types/#providers-TransactionReceipt)
// Invoke a smart contract on a blockchain
relayClient.invokeContract(
<function name>, // Name of the function to invoke
<contract address> // Smart contract address on the blockchain
<function abi>, // ABI of the function to invoke
<[funtion parameters array]>, // Array of function parameters
<chain id>, // Chain ID of the blockchain where the contract is deployed
// returns the transaction receipt type (refer to https://docs.ethers.org/v5/api/providers/types/#providers-TransactionReceipt)
// Transfer DPLAT tokens from one account to another
relayClient.transferDplat(
<chain id>, // Chain ID of the blockchain where the DPLAT token contract is deployed
<receiver address>, // Receiver's address
<amount>, // Amount of DPLAT tokens to transfer
)
//Upon completion, it returns the workflow ID. You can then utilize the '/relay/v1/workflow/{id}/status' API from the Relay APIs to retrieve the status of the transaction
// Approve DPLAT tokens to an account to grant spending rights
relayClient.approveDplat(
<chain id>, // Chain ID of the blockchain where the DPLAT token contract is deployed
<spender address>, // Spender's address
<amount>, // Amount of DPLAT tokens to approve
)
//Upon completion, it returns the workflow ID. You can then utilize the '/relay/v1/workflow/{id}/status' API from the Relay APIs to retrieve the status of the transaction
// Deposit DPLAT tokens as a credit to become payer, the payer address will be taken from his wallet
relayClient.depositDplat(
<amount>, // Amount of DPLAT tokens to deposit
<chainId>, // ChainId of blockchain to deposit dplat
)
//Upon completion, it returns the transaction receipt of deposit transaction
Refer to this example for guidance on using the SDK
License
For further inquiries or support, please contact [email protected].