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
npm install --save @magic-ext/taquito
#Yarn
yarn add @magic-ext/taquito
#Initializing Extension
#ES Modules/TypeScript
import { Magic } from 'magic-sdk';
import { TaquitoExtension } from '@magic-ext/taquito';
const magic = new Magic('YOUR_API_KEY', {
extensions: [
new TaquitoExtension({
rpcUrl: 'TEZOS_RPC_NODE_URL',
}),
],
});
#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
import { Magic } from 'magic-sdk';
import { TaquitoExtension } from '@magic-ext/taquito';
const magic = new Magic('YOUR_API_KEY', {
extensions: [
new TaquitoExtension({
rpcUrl: 'TEZOS_RPC_NODE_URL',
}),
],
});
const Tezos = new TezosToolkit('https://rpc.ithacanet.teztnets.xyz');
const magicSigner = await magic.taquito.createMagicSigner();
Tezos.setProvider({signer: magicSigner});
const operation = await Tezos.contract.transfer({ to: destinationAddress, amount: sendXTZAmount })
console.log('result', operation)