Klaytn’de Tatum-SDK nasıl kullanılır (Bölüm 1)
Tatum birleşik bir araç ve SDK’dır. Geliştiricilere, Web3’ü oluşturmak ve projelerine entegre etmek için kullanımı kolay bir platform sağlar. Tatum, seçtiğiniz herhangi bir blok zincirine dağıtılabilen, kullanıma hazır, standartlaştırılmış token akıllı sözleşmeler sunar. Bu, tek bir API çağrısında yapılabilir ve kendi sözleşmelerinizi oluşturmanızı ve dağıtmanızı gerektirmez.
Bu kılavuzda, Tatum SDK’nın akıllı sözleşme işlevlerinden bazılarını keşfedeceksiniz:
- Değiştirilebilir Jetonlar (ERC20);
- Değiştirilemez Jetonlar (ERC721);
- Çoklu Jeton(ERC1155) ve;
- Mevcut sözleşme yöntemlerini çağırma
Bu kılavuz, Klaytn’de Tatum SDK nasıl kullanılır? ve bu öğreticiyi başarıyla tamamlamak için Tatum-js’yi kurmuş ve çalışma dizininizi yapılandırmış olmalısınız.
Bu bölüm, değiştirilebilir belirteçlerin konuşlandırılması da dahil olmak üzere Tatum SDK’nın akıllı sözleşme özelliklerinden bazılarını tartışacaktır (ERC20), değiştirilemez belirteçler (ERC721) ve çoklu belirteçler (ERC1155).
Ek olarak, adresi ve ABI verilen mevcut bir sözleşme yöntemini çağırmanın yanı sıra, her bir belirteç sözleşmesinde nane, aktarım ve yazma işlevlerini çalıştırmak için Tatum SDK’yı nasıl kullanacağınızı keşfedeceksiniz.
Bu özellikler hakkında daha fazla bilgi için tıklayın Burada
ERC20 Simgesi Oluşturma
Aşağıdaki adım adım kılavuzla, ERC20 gerekli parametrelerin sağlanması koşuluyla, birkaç satır kodla temel işlevleri belirtebilir ve çağırabilirsiniz.
Kurmak
- Mevcut proje dizininize gidin
- Mevcut betikler klasörünü girin
- Kodu barındırmak için “erc20.js” adlı yeni bir dosya oluşturun
Tatum SDK’yı Başlat
Tatum’un yerleşik özelliklerini projenizde kullanmak için SDK’yı API KEY’inizle başlatmalısınız. Henüz bir API ANAHTARINIZ yok, bir tane oluşturun Burada.
import TatumKlaytnSDK from '@tatumio/klaytn'
const klaytnSDK = TatumKlaytnSDK( apiKey: '’ )
Değişkenleri ayarla
Yeni oluşturduğunuz erc20.js dosyanıza aşağıdaki değişkenleri kopyalayıp yapıştırın. Cüzdan adresinizi ve özel anahtarınızı aşağıdaki gibi herhangi bir cüzdan Altyapısından yapıştırabilirsiniz. Meta Maske veya bu önceki makalede açıklandığı gibi Tatum SDK’yı kullanarak bir tane oluşturun.
// This address will DEPLOY, MINT and TRANSFER ERC20 to Receiver Address
const senderAddress = ‘’const senderPrivateKey = ‘’
// This address will RECEIVE ERC20 token and BURN it
const receiverAddress = ‘’
const receiverPrivateKey = ‘’
NOT
Özel anahtarlarla çalışma
Bu bölümde kullanılacak kod sadece test ve demo amaçlıdır.
Bununla birlikte, özel anahtarlarınız ve anımsatıcılarınız, üretimde kullanıldığında güvenlik çevrenizden asla ayrılmamalıdır. kullanmanızı tavsiye ederiz Tatum CLI’sı komut satırından veya karmaşık anahtar yönetim sisteminden, Tatum KMScüzdanları doğru ve güvenli bir şekilde oluşturmak ve özel anahtarlarla çalışmak.
A.) Bir ERC-20 Akıllı Sözleşmesini Dağıtma
Klaytn’de önceden oluşturulmuş bir ERC20 sözleşmesi dağıtmak için bu kod parçacığını “erc20.js” dosyanıza yapıştırmanız gerekir. Yanıt, konuşlandırdığınız akıllı sözleşmenin adresini alabileceğiniz bir işlem kimliği içerir.
async function erc20Deploy ()
// deploys erc20 (fungible token) transactionconst erc20Deployed = await klaytnSDK.erc20.send.deploySignedTransaction(
symbol: 'MTK',
name: 'MyToken',
address: senderAddress,
supply: '10000',
fromPrivateKey: senderPrivateKey,
digits: 18,
)
console.log(`Here is the transaction id $erc20Deployed.txId`);
// This timer is used to ensure the transaction above is confirmed and added to the block
// In a real application, the wait mechanism must be implemented properly without using this.
setTimeout(() =>
getContractAddress(erc20Deployed.txId)
, 10000);
async function getContractAddress(erc20Deployed)
// fetch deployed contract address from transaction hash
const transaction = await klaytnSDK.blockchain.smartContractGetAddress("KLAY", erc20Deployed)
console.log(`Here is the contract address $transaction.contractAddress`);
erc20Deploy()
İşlemin sonucunu görmek için aşağıdaki komutu çalıştırın.
node scripts/erc20.js
B.) Bir Adrese jeton basma
Yeni oluşturulan değiştirilebilir belirteçler, belirli bir blok zincir adresine basılabilir. Yeni jeton basmak için dağıtılan ERC20 jetonlarının sözleşme adresini sağlamanız gerekir. Yukarıdaki örnekten türetilen sözleşme adresini kullanabilirsiniz.
Yanıt, bir işlem kimliği ve “alıcının” bakiyesini içerir. Bu kod parçacığını çalışırken görmek için aşağıdaki “erc20.js” dosyanıza yapıştırın
async function erc20Minted(contractAddress)
// mint erc20(fungible token) to a specified addressconst erc20Mint = await klaytnSDK.erc20.send.mintSignedTransaction(
to: receiverAddress,
contractAddress: contractAddress,
amount: '1',
fromPrivateKey: senderPrivateKey,
)
console.log(`Minted erc20 token/s with txID $erc20Mint.txId`)
// This timer is used to ensure the transaction above is confirmed and added to the block
// In a real application, the wait mechanism must be implemented properly without using this.
setTimeout(() =>
getErc20Balance(receiverAddress, contractAddress)
, 10000);
async function getErc20Balance(address, contractAddress)
// gets the number of the fungible tokens minted on a specific smart contract that a blockchain address holds.
const erc20Balance = await klaytnSDK.erc20.getErc20AccountBalance("KLAY", address, contractAddress);
console.log(erc20Balance);
Const contractAddress = “”
erc20Minted(contractAddress)
İşlem kimliğinizi ve alıcının yeni basılan jeton bakiyesini görmek için aşağıdaki komutu çalıştırın
node scripts/erc20.js
C.) ERC20 Jetonlarını Aktarma
Değiştirilebilir belirteçler, ` çağrılarak belirli bir blok zinciri adresine aktarılır.Aktar()` yöntemi. sözleşmeAdresi alanı, önceki örnekten elde edilen alanla değiştirilebilir.
Yanıt, bir işlem kimliğini ve transferden sonra “gönderenin” bakiyesini içerir. Bu kod parçacığını çalışırken görmek için aşağıdaki “erc20.js” dosyanıza yapıştırın
async function er20Transferred(contractAddress)
// send erc20 (fungible token) transactionconst erc20Transfer = await klaytnSDK.erc20.send.transferSignedTransaction(
to: receiverAddress,
amount: '1',
contractAddress,
fromPrivateKey: senderPrivateKey,
digits: 18,
)
console.log(`Transferred erc20 token/s with txID $erc20Transfer.txId`)
// This timer is used to ensure the transaction above is confirmed and added to the block
// In a real application, the wait mechanism must be implemented properly without using this.
setTimeout(() =>
getErc20Balance(senderAddress, contractAddress)
, 10000);
er20Transferred(contractAddress)
Bir transferden sonra işlem kimliğinizi ve gönderenin bakiyesini görmek için aşağıdaki komutu çalıştırın:
node scripts/erc20.js
D.) ERC20 Jetonlarının Yazılması
Karşılanabilir belirteçlerin yakılması, belirtilen kaynağı akıllı sözleşmeden siler. sözleşmeAdresi alanı, önceki örnekten elde edilen alanla değiştirilebilir.
Yanıt, yanan belirteçlerden sonra bir işlem kimliği ve “alıcının” bakiyesini içerir. Bu kod parçacığını çalışırken görmek için aşağıdaki “erc20.js” dosyanıza yapıştırın
async function erc20Burned(contractAddress)
// burn erc20 (fungible token) transactionconst erc20Burn = await klaytnSDK.erc20.send.burnSignedTransaction(
contractAddress: contractAddress,
amount: '1',
fromPrivateKey: receiverPrivateKey,
)
console.log(`Burned erc20 token/s with txID $erc20Burn.txId`)
// This timer is used to ensure the transaction above is confirmed and added to the block
// In a real application, the wait mechanism must be implemented properly without using this.
setTimeout(() =>
getErc20Balance(receiverAddress, contractAddress)
, 10000);
erc20Burned(contractAddress)
Jetonları yaktıktan sonra işlem kimliğinizi ve alıcı bakiyesini görmek için aşağıdaki komutu çalıştırın:
node scripts/erc20.js
Tam Kod
import TatumKlaytnSDK from '@tatumio/klaytn'
const klaytnSDK = TatumKlaytnSDK( apiKey: '’ )// This address will DEPLOY, MINT and TRANSFER ERC20 to Receiver Address
const senderAddress = ‘’
const senderPrivateKey = ‘’
// This address will RECEIVE ERC20 token and BURN it
const receiverAddress = ‘’
const receiverPrivateKey = ‘’
async function erc20Deploy ()
// deploys erc20 (fungible token) transaction
const erc20Deployed = await klaytnSDK.erc20.send.deploySignedTransaction(
symbol: 'MTK',
name: 'MyToken',
address: senderAddress,
supply: '10000',
fromPrivateKey: senderPrivateKey,
digits: 18,
)
console.log(`Here is the transaction id $erc20Deployed.txId`);
setTimeout(() =>
getContractAddress(erc20Deployed.txId)
, 10000);
async function getContractAddress(erc20Deployed)
// fetch deployed contract address from transaction hash
const transaction = await klaytnSDK.blockchain.smartContractGetAddress("KLAY", erc20Deployed)
console.log(`Here is the contract address $transaction.contractAddress`);
async function er20Transferred(contractAddress)
// send erc20 (fungible token) transaction
const erc20Transfer = await klaytnSDK.erc20.send.transferSignedTransaction(
to: receiverAddress,
amount: '1',
contractAddress,
fromPrivateKey: senderPrivateKey,
digits: 18,
)
console.log(`Transferred erc20 token/s with txID $erc20Transfer.txId`)
setTimeout(() =>
getErc20Balance(senderAddress, contractAddress)
, 10000);
async function erc20Minted(contractAddress)
// mint erc20(fungible token) to a specified address
const erc20Mint = await klaytnSDK.erc20.send.mintSignedTransaction(
to: receiverAddress,
contractAddress: contractAddress,
amount: '1',
fromPrivateKey: senderPrivateKey,
)
console.log(`Minted erc20 token/s with txID $erc20Mint.txId`)
setTimeout(() =>
getErc20Balance(receiverAddress, contractAddress)
, 10000);
async function erc20Burned(contractAddress)
// burn erc20 (fungible token) transaction
const erc20Burn = await klaytnSDK.erc20.send.burnSignedTransaction(
contractAddress: contractAddress,
amount: '3',
fromPrivateKey: receiverPrivateKey,
)
console.log(`Burned erc20 token/s with txID $erc20Burn.txId`)
setTimeout(() =>
getErc20Balance(receiverAddress, contractAddress)
, 10000);
async function getErc20Balance(address,contractAddress)
// gets the number of the fungible tokens minted on a specific smart contract that a blockchain address holds.
const erc20Balance = await klaytnSDK.erc20.getErc20AccountBalance("KLAY", address, contractAddress);
console.log(erc20Balance);
const contractAddress = “”
erc20Deploy()
er20Transferred(contractAddress);
getErc20Balance(receiverAddress,contractAddress);
erc20Burned(contractAddress);
erc20Minted(contractAddress);
ERC721 Jetonları Oluşturma
Aşağıdaki adım adım kılavuzla, ERC721 gerekli parametrelerin doldurulması koşuluyla, birkaç satır kodla temel işlevleri belirteç ve çağırın.
Bu bölümde, aşağıdakileri yapabileceksiniz:
- ERC721 sözleşmesini dağıtın
- Nane tek ve çoklu ERC721 belirteçleri
- NFT belirteci Meta Verilerini Alın
- NFT’leri aktarın
- NFT’leri yakma
Öncelikle yeni bir erc721.js dosyası oluşturmanız gerekiyor. Kodlar klasörünü açın ve Tatum SDK’yı başlatın ve ‘ERC20 Belirteçleri Oluşturma’ bölümünde yaptığınız gibi değişkenleri ayarlayın.
İkinci olarak, aşağıdaki kodu erc721.js dosyanıza yapıştırın ve her işlevin sonucunu görmek için aşağıdaki komutu çalıştırın.
node scripts/erc721.js
A. Bir NFT akıllı sözleşmesi dağıtın
Aşağıdaki kod parçacıklarıyla Klaytn blok zincirinde bir NFT akıllı sözleşmesi dağıtın. Bu dağıtılan NFT akıllı sözleşmesi, NFT’leri (her seferinde bir NFT veya aynı anda birden çok NFT) basmanıza, NFT’leri yazmanıza ve aktarmanıza olanak tanır.
async function erc721Deploy ()
// deploys erc721 (non-fungible token) transactionconst nftDeploy = await klaytnSDK.nft.send.deploySignedTransaction(
name: 'My NFT',
symbol: 'MNFT',
// your private key of the address that has coins
fromPrivateKey: senderPrivateKey,
)
console.log(`Here is the transaction id $nftDeploy.txId`);
setTimeout(() =>
getContractAddress(nftDeploy.txId)
, 10000);
async function getContractAddress(erc721Deployed)
// fetch deployed contract address from transaction hash
const transaction = await klaytnSDK.blockchain.smartContractGetAddress("KLAY", erc721Deployed)
console.log(`Here is the contract address $transaction.contractAddress`);
erc721Deploy()
Çıktı
B. NFT bas
Bu kod satırlarıyla, sözleşme adresiniz ve belirteç kimliğiniz verilen Klaytn blok zincirinde yerel olarak bir NFT basabilirsiniz.
Not: Bu işlev, IPFS karmasını gerektirir. meta veri. Bunu izleyerek meta verilerinizi IPFS’ye yükleyebilirsiniz. rehber.
async function nftMint(contractAddress)
// Mint NFTs on your own smart contract// Put any number here. For a start 1
const tokenId = '';
const nftMinted = await klaytnSDK.nft.send.mintSignedTransaction(
chain: "KLAY",
tokenId,
contractAddress,
fromPrivateKey: senderPrivateKey,
to: senderAddress,
// uploaded metadata from ipfs
url: '’,
)
console.log(`Minted nft with txID: $nftMinted.txId`)
Const contractAddress = “”
nftMint(contractAddress)
Çıktı
C. Nane Çoklu NFT
Bu yöntem kullanılarak belirli bir blockchain adresine birden fazla NFT Jetonu basılabilir.
async function nftMintBatch(contractAddress)
// Mint multiple NFTs on your own smart contractconst nftMinted = await klaytnSDK.nft.send.mintMultipleSignedTransaction(
chain: "KLAY",
tokenId: (“", ""),
contractAddress,
fromPrivateKey: senderPrivateKey,
to: (senderAddress, receiverAddress),
// uploaded metadata from ipfs
url: (“”, “PASTE IPFS HASH HERE”)
)
console.log(`Minted multiple nft with txID: $nftMinted.txId`)
Çıktı
D. Koleksiyondaki tüm basılmış NFT’leri alın
async function getContractNftBalance(contractAddress)
// Get all minted NFTs in the collection. Returns all NFTs this contract minted.const nftAccountBalance = await klaytnSDK.nft.getNFTAccountBalance(
"KLAY",
senderAddress,
contractAddress,
)
console.log(`Nfts on $contractAddress:`, nftAccountBalance)
getContractNftBalance(contractAddress)
Çıktı
E. NFT belirteci meta verilerini alın
async function getNFTMetadata(contractAddress, tokenId)
// Get NFT token metadataconst response = await klaytnSDK.nft.getNFTMetadataURI("KLAY", contractAddress, tokenId)
console.log(`Token metadata: $JSON.stringify(response)`)
Const tokenId = <”VALID TOKEN ID”>
getNFTMetadata(contractAddress, tokenId)
Çıktı
F. NFT’yi aktarın
Akıllı sözleşme adresi verilen belirtilen blockchain adresine akıllı sözleşmeden bir NFT aktarın
async function transferNFT(contractAddress, tokenId)
const nftTransferred = await klaytnSDK.nft.send.transferSignedTransaction(to: receiverAddress,
tokenId,
contractAddress,
fromPrivateKey: senderPrivateKey,
)
console.log(`Transferred nft with transaction hash: $nftTransferred.txId`)
transferNFT(contractAddress, tokenId)
Not: Gönderenin belirteç kimliğine bağlı bir NFT’ye sahip olduğundan emin olun
Çıktı
G. NFT’yi Yaz
NFT’yi yakmak, onu kimsenin erişemeyeceği sıfır adresine aktarır.
async function burnNFT(contractAddress, tokenId)
// Burn one NFT Token. This method destroys any NFT token from smart contract defined in contractAddress.const nftBurned = await klaytnSDK.nft.send.burnSignedTransaction(
tokenId,
contractAddress,
fromPrivateKey: receiverPrivateKey,
)
console.log(`NFT burn transaction sent with txID: $nftBurned.txId`)
burnNFT(contractAddress, tokenId)
Not: Alıcının belirteç kimliğine bağlı bir NFT’ye sahip olduğundan emin olun
Çıktı
Tam Kod
import TatumKlaytnSDK from '@tatumio/klaytn'
const klaytnSDK = TatumKlaytnSDK( apiKey: '’ )// This address will DEPLOY, MINT and TRANSFER ERC20 to Receiver Address
const senderAddress = ‘’
const senderPrivateKey = ‘’
// This address will RECEIVE ERC20 token and BURN it
const receiverAddress = ‘’
const receiverPrivateKey = ‘’
async function erc721Deploy ()
// deploys erc721 (non fungible token) transaction
const nftDeploy = await klaytnSDK.nft.send.deploySignedTransaction(
name: 'My NFT',
symbol: 'MNFT',
// your private key of the address that has coins
fromPrivateKey: senderPrivateKey,
)
console.log(`Here is the transaction id $nftDeploy.txId`);
setTimeout(() =>
getContractAddress(nftDeploy.txId)
, 10000);
async function getContractAddress(erc721Deployed)
// fetch deployed contract address from transaction hash
const transaction = await klaytnSDK.blockchain.smartContractGetAddress("KLAY", erc721Deployed)
console.log(`Here is the contract address $transaction.contractAddress`);
async function nftMint(contractAddress)
// Mint NFTs on your own smart contract
// Put any number here. For a start 1
const tokenId = '';
const nftMinted = await klaytnSDK.nft.send.mintSignedTransaction(
chain: "KLAY",
tokenId,
contractAddress,
fromPrivateKey: senderPrivateKey,
to: senderAddress,
// uploaded metadata from ipfs
url: '’,
)
console.log(`Minted nft with txID: $nftMinted.txId`)
async function nftMintBatch(contractAddress)
// Mint multiple NFTs on your own smart contract
const nftMinted = await klaytnSDK.nft.send.mintMultipleSignedTransaction(
chain: "KLAY",
tokenId: (“", ""),
contractAddress,
fromPrivateKey: senderPrivateKey,
to: (senderAddress, receiverAddress),
// uploaded metadata from ipfs
url: (“”, “PASTE IPFS HASH HERE”)
)
console.log(`Minted multiple nft with txID: $nftMinted.txId`)
async function getContractNftBalance(contractAddress)
// Get all minted NFTs in the collection. Returns all NFTs this contract minted.
const nftAccountBalance = await klaytnSDK.nft.getNFTAccountBalance(
"KLAY",
senderAddress,
contractAddress,
)
console.log(`Nfts on $contractAddress:`, nftAccountBalance)
async function getNFTMetadata(contractAddress, tokenId)
// Get NFT token metadata
const response = await klaytnSDK.nft.getNFTMetadataURI("KLAY", contractAddress, tokenId)
console.log(`Token metadata: $JSON.stringify(response)`)
async function transferNFT(contractAddress, tokenId)
// Transfer an NFT from the smart contract (the contractAddress parameter in the request body) to the specified blockchain address (the to parameter in the request body).
const nftTransferred = await klaytnSDK.nft.send.transferSignedTransaction(
to: receiverAddress,
tokenId,
contractAddress,
fromPrivateKey: senderPrivateKey,
)
console.log(`Transferred nft with transaction hash: $nftTransferred.txId`)
async function burnNFT(contractAddress, tokenId)
// Burn one NFT Token. This method destroys any NFT token from smart contract defined in contractAddress.
const nftBurned = await klaytnSDK.nft.send.burnSignedTransaction(
tokenId,
contractAddress,
fromPrivateKey: receiverPrivateKey,
)
console.log(`NFT burn transaction sent with txID: $nftBurned.txId`)
const contractAddress = "";
const tokenId = "";
erc721Deploy();
nftMint(contractAddress);
nftMintBatch(contractAddress);
getContractNftBalance(contractAddress);
getNFTMetadata(contractAddress, tokenId);
transferNFT(contractAddress, tokenId);
burnNFT(contractAddress, tokenId);
ERC1155 Simgesi Oluşturma
Aşağıdaki adım adım kılavuzla, eşdeğeri olan ERC1155 belirtecinizi konuşlandırabileceksiniz. KIP37 klaytn blok zincirinde. Ayrıca, gerekli parametrelerin doldurulması koşuluyla, birkaç satır kodla temel işlevleri çağıracaksınız.
Bu bölümde, aşağıdakileri yapabileceksiniz:
- ERC1155 sözleşmesini dağıtın
- Nane ERC1155 belirteçleri
- Çoklu Jeton Transferi(MT)
- Çoklu belirteçleri yakma(MT)
Öncelikle yeni bir erc1155.js dosyası oluşturmanız gerekiyor. Kodlar klasörünü açın ve Tatum SDK’yı başlatın ve ‘ERC20 Simgeleri Oluşturma’ bölümünde yaptığınız gibi değişkenleri ayarlayın.
İkinci olarak, aşağıdaki kodu erc721.js dosyanıza yapıştırın ve her işlevin sonucunu görmek için aşağıdaki komutu çalıştırın.
>düğüm betikleri/erc1155.js
A. ERC1155 sözleşmesini dağıtın
Bu yöntem, Klaytn blok zincirinde yeni bir ERC1155 Akıllı Sözleşme (Çoklu Jeton) oluşturur. ERC1155 sözleşmenizi dağıttıktan sonra, jeton basmak, yakmak ve transfer etmek mümkündür.
async function erc1155Deploy ()
// deploys Multi token transactionconst multiTokenDeployed = await klaytnSDK.multiToken.send.deployMultiTokenTransaction(
// your private key of the address that has coins
fromPrivateKey: senderPrivateKey,
// uploaded metadata from ipfs
uri: 'ipfs://bafkreidinxo4cuds5ybcl72al5sywstc3m6i7lwmkz5wcdna7ccadjssm4',
)
console.log(`Deployed multi token with txID $multiTokenDeployed.txId`)
setTimeout(() =>
getContractAddress(multiTokenDeployed.txId)
, 10000);
async function getContractAddress(multiTokenDeployed)
// fetch deployed contract address from transaction hash
const transaction = await klaytnSDK.blockchain.smartContractGetAddress("KLAY", multiTokenDeployed)
console.log(`Here is the contract address $transaction.contractAddress`);
erc1155Deploy()
Not: Bu işlev, IPFS karmasını gerektirir. meta veri. Bunu izleyerek meta verilerinizi IPFS’ye yükleyebilirsiniz. rehber.
Çıktı
B. Çoklu Jeton Basma
Bu yöntemle, belirli bir blockchain adresine sabit miktarda Multi Token basabilirsiniz.
async function mintmultiToken(contractAddress)
// Paste a number lets say 1 const tokenId = ""
const multiTokenMinted = await klaytnSDK.multiToken.send.mintMultiTokenTransaction(
to: senderAddress,
tokenId,
amount: '1000',
fromPrivateKey: senderPrivateKey,
contractAddress,
)
console.log(`Multi Token mint transaction sent with txID: $multiTokenMinted.txId`)
const contractAddress = “”
mintmultiToken(contractAddress)
Çıktı
C. Bir Çoklu Jetonu Aktarın
Bu yöntemi kullanarak bir hesaptan başka bir hesaba belirli miktarda Multi Token aktarabilirsiniz.
async function transferMT(contractAddress, tokenId)
// Transfer multi-token from the smart contract to the specified blockchain addressconst multiTokenTransferred = await klaytnSDK.multiToken.send.transferMultiTokenTransaction(
to: receiverAddress,
tokenId,
amount: '10',
fromPrivateKey: senderPrivateKey,
contractAddress,
)
console.log(`Sent Multi Token with txID: $multiTokenTransferred.txId`)
const tokenId=“”
transferMT(contractAddress, tokenId)
Çıktı
D. Çoklu Jeton Yazma
Bu yöntem kimliğe göre sabit miktarda Çoklu Jeton yakar. Sözleşme Adresinde tanımlanan akıllı sözleşmeden Çoklu Belirteçleri yok eder.
async function burnMT(contractAddress, tokenId)
// Burn one multi-token. This method destroys any MT token from smart contract defined in contractAddress.const multiTokenBurned = await klaytnSDK.multiToken.send.burnMultiTokenTransaction(
tokenId,
amount: '1',
fromPrivateKey: receiverPrivateKey,
contractAddress,
account: receiverAddress,
)
console.log(`Burned Multi Token/s with txID: $multiTokenBurned.txId`)
burnMT(contractAddress, tokenId)
Çıktı
Tam Kod
import TatumKlaytnSDK from '@tatumio/klaytn'
const klaytnSDK = TatumKlaytnSDK( apiKey: '’ )// This address will DEPLOY, MINT and TRANSFER ERC20 to Receiver Address
const senderAddress = ‘’
const senderPrivateKey = ‘’
// This address will RECEIVE ERC20 token and BURN it
const receiverAddress = ‘’
async function erc1155Deploy ()
// deploys Multi token transaction
const multiTokenDeployed = await klaytnSDK.multiToken.send.deployMultiTokenTransaction(
// your private key of the address that has coins
fromPrivateKey: senderPrivateKey,
// uploaded metadata from ipfs
uri: '’,
)
console.log(`Deployed multi token with txID $multiTokenDeployed.txId`)
setTimeout(() =>
getContractAddress(multiTokenDeployed.txId)
, 10000);
async function getContractAddress(multiTokenDeployed)
// fetch deployed contract address from transaction hash
const transaction = await klaytnSDK.blockchain.smartContractGetAddress("KLAY", multiTokenDeployed)
console.log(`Here is the contract address $transaction.contractAddress`);
async function mintmultiToken(contractAddress)
// Paste a number lets say 1
const tokenId = ""
const multiTokenMinted = await klaytnSDK.multiToken.send.mintMultiTokenTransaction(
to: senderAddress,
tokenId,
amount: '1000',
fromPrivateKey: senderPrivateKey,
contractAddress,
)
console.log(`Multi Token mint transaction sent with txID: $multiTokenMinted.txId`)
async function transferMT(contractAddress, tokenId)
// Transfer multi-token from the smart contract to the specified blockchain address
const multiTokenTransferred = await klaytnSDK.multiToken.send.transferMultiTokenTransaction(
to: receiverAddress,
tokenId,
amount: '10',
fromPrivateKey: senderPrivateKey,
contractAddress,
)
console.log(`Sent Multi Token with txID: $multiTokenTransferred.txId`)
async function burnMT(contractAddress, tokenId)
// Burn one multi-token. This method destroys any MT token from the smart contract defined in contractAddress.
const multiTokenBurned = await klaytnSDK.multiToken.send.burnMultiTokenTransaction(
tokenId,
amount: '1',
fromPrivateKey: receiverPrivateKey,
contractAddress,
account: receiverAddress,
)
console.log(`Burned Multi Token/s with txID: $multiTokenBurned.txId`)
const contractAddress = "0x5C128284F7846698134228e4a197664DE075AcDB";
const tokenId = "1"
erc1155Deploy();
mintmultiToken(contractAddress)
transferMT(contractAddress, tokenId);
burnMT(contractAddress, tokenId);
Klaytn’de bir akıllı sözleşmede bir yöntem çağırın
Bu bölümde, Klaytn’de mevcut bir akıllı sözleşmede bir yöntemi çağırmak için Tatum SDK’yı kullanacaksınız. İşleri bir perspektife oturtmak için, önceden konuşlandırılmış sözleşme yönteminiz, Tatum-js kullanılarak sözleşme adresi ve ABI verildiğinde yürütülebilir.
yürütebilirsiniz Sadece oku veya yazmak yöntem. A Sadece oku yöntem, çağrılan yöntemin çıktısını döndürürken, işlem kimliği bir yazmak yöntem döndürülür.
Kurmak
- Mevcut proje dizininize gidin
- Mevcut betikler klasörünü girin
- Kodu barındırmak için “invoke.js” adlı yeni bir dosya oluşturun
Tatum SDK’yı Başlat
Tatum’un yerleşik özelliklerini projenizde kullanmak için SDK’yı API KEY’inizle başlatmalısınız. Henüz bir API ANAHTARINIZ yok, bir tane oluşturun Burada
import TatumKlaytnSDK from '@tatumio/klaytn'
const klaytnSDK = TatumKlaytnSDK( apiKey: '’ )
Değişkenleri ayarla
Yeni oluşturduğunuz ‘invoke.js’ dosyanıza aşağıdaki değişkenleri kopyalayıp yapıştırın. Cüzdan adresinizi ve özel anahtarınızı aşağıdaki gibi herhangi bir cüzdan Altyapısından yapıştırabilirsiniz. Meta Maske veya içinde açıklandığı gibi Tatum SDK’yı kullanarak bir tane oluşturun. önceki makale.
const senderPrivateKey = “”
Hızlı başlangıç
Mevcut bir akıllı sözleşme yöntemini çağırmak için sözleşme adresini ve ABI’yi almanız gerekir. Bu eğitimde, mevcut bir Banka sözleşmesi devreye alındı ve bu nedenle, her ikisine de çağrı yapacaktık. dengeyi sağlamak Ve Depozito fonksiyonlar.
Banka sözleşmenizi devreye almak için buna tıklayın bağlantı açmak remiks. Sözleşmeniz dağıtıldıktan sonra, sözleşme adresini şu adresten kopyalayın: Dağıtılan Sözleşmeler sekmesi ve ABI Sağlamlık Derleyici Remix IDE’deki sekme.
Her işlevin sonucunu görmek için aşağıdaki komutu çalıştırın.
>düğüm betikleri/invoke.js
A. Okuma Yöntemi
Aşağıdaki kod satırlarıyla akıllı sözleşmenizde bir okuma yöntemi çağırın.
async function readFromSmartContract ()
const address = “”// your previously deployed contract address
const contractAddress = “”
// smart contract read method
const data = await klaytnSDK.smartContract.send.smartContractReadMethodInvocationTransaction(
contractAddress: contractAddress,
methodABI:
"inputs": (
"internalType": "address",
"name": "_addr",
"type": "address"
),
"name": "getBalance",
"outputs": (
"internalType": "uint256",
"name": "",
"type": "uint256"
),
"stateMutability": "view",
"type": "function"
,
methodName: "getBalance",
params: (address)
)
console.log(`Smart contract data: $data.data`)
Çıktı
B. Yazma Yöntemi
Aşağıdaki kod satırlarıyla akıllı sözleşmenizde bir yazma yöntemi çağırın.
async function invokeWriteMethod ()
// your previously deployed contract addressconst contractAddress = “”
// smart contract read method
const data = await klaytnSDK.smartContract.send.smartContractMethodInvocationTransaction(
amount: "2",
contractAddress: contractAddress,
methodABI:
"inputs": (),
"name": "deposit",
"outputs": (),
"stateMutability": "payable",
"type": "function"
,
methodName: "deposit",
fromPrivateKey: senderPrivateKey,
params: ()
)
console.log(`Smart contract tx id: $ data.txId `)
Çıktı
tatum geliştiricilere çeşitli şekillerde yardımcı olduğu için kendisini çok sayıda blok zinciri için açık kaynaklı bir geliştirme platformu olarak konumlandırır. Bu öğreticide, akıllı sözleşmeler ve token sözleşmeleri (ERC20, ERC721 ve ERC1155) ile çalışmayı ve ayrıca Klaytn’de mevcut bir akıllı sözleşme üzerinde bir yöntem çağırmayı araştırdık.
Bununla birlikte, kullanıcılar internet üzerinden hassas veriler göndermeden işlemleri yerel olarak güvenli bir şekilde imzalayabilir ve yayınlayabilir. Bu, özel anahtarlar ve anımsatıcılarla uğraşırken kullanıcılar için yüksek düzeyde güvenlik sağlar. Bu güvenlik odaklı işlevi denemek istiyorsanız, şuraya göz atın: Tatum Anahtar Yönetim Sistemi(KMS) işlemleri güvenli bir şekilde imzalamak ve Klaytn blok zincirinde yayınlamak için.
Daha fazla bilgi istiyorsanız, ziyaret edin Klaytn Belgeleri Ve tatum. Herhangi bir sorunuz varsa, ziyaret edin Klaytn Forumu.