Contract API
Initializing
Instantiating the Contract API.
// web3Api.ts
import naxios from '@wpdas/naxios'
const naxiosInstance = new naxios({
contractId: 'dev-1692221685438-15421910364142',
network: 'testnet',
})
/**
* Greeting Contract API
*/
export const greetingContractApi = naxiosInstance.contractApi()You can instantiate it using a cache system too:
// web3Api.ts
import naxios, { StorageCache } from '@wpdas/naxios'
const naxiosInstance = new naxios({
contractId: 'dev-1692221685438-15421910364142',
network: 'testnet',
})
/**
* Cached - Greeting Contract API
*/
const cache = new StorageCache({ expirationTime: 60 }) // expiration time in seconds
export const greetingContractApi = naxiosInstance.contractApi({ cache })Get to know more about the cache system by clicking on the link below:
Cache SystemAPI Reference
view: Make a read-only call to retrieve information from the network. It has the following parameters:method: Contract's method name.props?: an optional parameter withargsfor the contract's method.config?: currently, this has only theuseCacheprop. When useCache is true, this is going to use non-expired cached data instead of calling the contract's method.
call: Call a method that changes the contract's state. This is payable. It has the following parameters:method: Contract's method nameprops?: an optional parameter withargsfor the contract's method,gas,depositto be attached andcallbackUrlif you want to take the user to a specific page after a transaction succeeds.
callMultiple: Call multiple methods that change the contract's state. This is payable and has the following parameters:transactionsList: A list of Transaction props. You can usebuildTransaction(...)to help you outcallbackUrl?: A page to take the user to after all the transactions succeed.
Contract View
Using a view method is free.
Contract Call
You need to pay for every request you make for acall method. This is going to change data and store it within the blockchain.
Contract Multiple Calls at Once
As well as the call, you will need to pay for every request you make. This is going to change data and store it within the blockchain.
Last updated