UNPKG

@massalabs/massa-web3

Version:
68 lines 2.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SmartContract = void 0; const helpers_1 = require("../provider/helpers"); /** * A class to interact with a smart contract. */ class SmartContract { provider; address; constructor(provider, address) { this.provider = provider; this.address = address; } /** * Executes a smart contract call operation * @param func - The smart contract function to be called. * @param parameter - Parameters for the function call in Uint8Array or number[] format. * @param options - Includes optional and required parameters like fee, maxGas, coins, and periodToLive. * @returns A promise that resolves to an Operation object representing the transaction. */ async call(func, args = new Uint8Array(), options = {}) { const callParams = { func, parameter: args, target: this.address, ...options, }; if ((0, helpers_1.isProvider)(this.provider)) { return this.provider.callSC(callParams); } throw new Error('Provider does not support callSC'); } /** * Executes a smart contract read operation * @param func - The smart contract function to be called. * @param args - Parameter for the function call in Uint8Array format. * @param options - Includes optional parameters like fee, maxGas, coins, and periodToLive. * @returns A promise that resolves to the result of the read operation. */ async read(func, args = new Uint8Array(), options = {}) { const readParams = { func, parameter: args, target: this.address, ...options, }; return this.provider.readSC(readParams); } /** * Deploy a SmartContract byteCode * @param provider - Web3 provider. * @param byteCode - Compiled SmartContract bytecode. * @param constructorArgs - Parameter for call of constructor function. * @param options - Includes optional parameters like fee, maxGas, coins, and periodToLive. * @returns A promise that resolves to the result of the read operation. */ static async deploy(provider, byteCode, constructorArgs = new Uint8Array(), options = {}) { const deployParams = { byteCode, parameter: constructorArgs, ...options, }; return provider.deploySC(deployParams); } } exports.SmartContract = SmartContract; //# sourceMappingURL=smartContract.js.map