How to Integrate with the Tezos Blockchain with Magic and Taquito
How to Integrate with the Tezos Blockchain with Magic and Taquito
#Installation
Magic interacts with the Tezos blockchain via Magic's extension NPM package @magic-ext/taquito
. The Tezos extension also lets you interact with the blockchain using methods from Tezos's Taquito SDK.
You can skip straight to our kitchen sink example directly:
#NPM
01npm install --save @magic-ext/taquito
#Yarn
01yarn add @magic-ext/taquito
#Initializing Extension
#ES Modules/TypeScript
01import { Magic } from 'magic-sdk';
02import { TaquitoExtension } from '@magic-ext/taquito';
03
04const magic = new Magic('YOUR_API_KEY', {
05 extensions: [
06 new TaquitoExtension({
07 rpcUrl: 'TEZOS_RPC_NODE_URL',
08 }),
09 ],
10});
#Send Transaction
#Call Extension Method
Note that the Magic Taquito extension follows the method names and conventions by Taquito. To send a standard Tezos blockchain transaction, you can call the magic.taquito.createMagicSigner
method to create a signer to inject to Tezos client.
#ES Modules/TypeScript
01import { Magic } from 'magic-sdk';
02import { TaquitoExtension } from '@magic-ext/taquito';
03
04const magic = new Magic('YOUR_API_KEY', {
05 extensions: [
06 new TaquitoExtension({
07 rpcUrl: 'TEZOS_RPC_NODE_URL',
08 }),
09 ],
10});
11
12const Tezos = new TezosToolkit('https://rpc.ithacanet.teztnets.xyz');
13const magicSigner = await magic.taquito.createMagicSigner();
14
15Tezos.setProvider({signer: magicSigner});
16
17const operation = await Tezos.contract.transfer({ to: destinationAddress, amount: sendXTZAmount })
18
19console.log('result', operation)