-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtc4_transferNFT.js
More file actions
41 lines (30 loc) · 1.28 KB
/
tc4_transferNFT.js
File metadata and controls
41 lines (30 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require('dotenv').config();
const { ethers } = require("ethers");
const chalk = require("chalk");
//Contract details
const artifact = require("./build/contracts/NonFungibleTokenContract.json");
const network = "rinkeby";
//Instantiations
const provider = new ethers.providers.InfuraProvider(network, {
projectId: process.env.projectId,
projectSecret: process.env.projectSecret
});
const wallet = new ethers.Wallet(process.env.privateKey, provider);
const contract = new ethers.Contract(process.env.nftAddress, artifact.abi, wallet);
//Transfer a token from wallet holder (account1) to account2
(async function () {
//Transfer details
let from = process.env.address;
let to = process.env.address2;
let id = 2;
let args = [from, to, id];
//Transfer token
let transaction = await contract.transferFrom(...args);
let result = await transaction.wait();
//You can now add the contract address to the .env file (ftAddress)
console.log(chalk.green(`Success! Visit etherscan for details:`));
//You can inspect the transaction on Etherscan
console.log(chalk.blue(`https://rinkeby.etherscan.io/tx/${result.transactionHash}`));
//You can inspect the token transfer activity on Etherscan
console.log(chalk.blue(`https://rinkeby.etherscan.io/token/${contract.address}`));
})();