Skip to main content

Simple Contract Call

The following example shows how to do a simple contract call with beacon.

tip

The beacon-sdk itself does not do any type checking on the parameters you pass. Use taquito if you don't want to construct the parameters yourself.

The wallet will process and validate the operation. If there are any errors, they have to be displayed in the wallet. run_operation errors can optionally be sent back to the dApp as well.

import { DAppClient, TezosOperationType } from "@airgap/beacon-sdk";
// Create a new DAppClient instance
const dAppClient = new DAppClient({ name: "Beacon Docs" });
const activeAccount = await dAppClient.getActiveAccount();
if (activeAccount) {
// User already has account connected, everything is ready
// You can now do an operation request, sign request, or send another permission request to switch wallet
console.log("Already connected:", activeAccount.address);
} else {
const permissions = await dAppClient.requestPermissions();
console.log("New connection:", permissions.address);
}
const TZ_BUTTON_COLORS_CONTRACT = "KT1RPW5kTX6WFxg8JK34rGEU24gqEEudyfvz";
const tokenId = "925";
// Setting the color of TzButton is only possible if you are currently the leader and own a color
// So this call will likely fail
try {
const result = await dAppClient.requestOperation({
operationDetails: [
{
kind: TezosOperationType.TRANSACTION,
amount: "0",
destination: TZ_BUTTON_COLORS_CONTRACT,
parameters: {
entrypoint: "set_color",
value: {
int: tokenId,
},
},
},
],
});
console.log(result);
} catch (error) {
console.log(
`The contract call failed and the following error was returned:`,
error?.data[1]?.with?.string
);
}
https://example.com