How to transfer OpenSea Matic ERC-1155 using Node.js backend?

So I saw this example:
https://docs.moralis.io/moralis-server/sending-assets#transferring-erc1155-tokens-semi-fungible

And thought:

“wow, that’s so easy!”

But then when I tried figuring out authentication, all the examples I could find were for frontend code, not backend.

How can I add authentication (either via web3 or truffle) using the MetaMask mnemonic passed into Node from command-line?

Thanks in advance! You guys seem to be doing some really cool stuff so far :grin:

1 Like

For now we don’t have support for server side node js in Moralis SDK for transfer function. We plan to add it soon. For now you can use web3 to do that.

This is an example of using web3 to make a native currency transfer:

const Moralis = require('moralis/node')
const Web3 = require('web3')

//Local ganache 
const web3 = new Web3("HTTP://127.0.0.1:7545")
private_key = 'PRIVATE_KEY'
web3.eth.accounts.wallet.add(private_key);

console.log(web3.eth.accounts.wallet[0]);

web3.eth.sendTransaction({
          from: 0,
          to: "DESTINATION_ADDRESS",
          value: Moralis.Units.ETH("0.6"),
          gas: 21000,
        });

Ok thank you!

Would this web3 example above work for ERC-1155 tokens on the Matic network? It’s weird that I can’t seem to find any example anywhere in Google regarding this :thinking:

No, that example will not work with ERC-1155 tokens, for that case you’ll have to call safeTransferFrom function for the specific smart contract address that has the tokens that you want to transfer.

Ahhh ok, so this is only possible with Solidity (not Node)? Sorry for my ignorance, kind of overwhelmed :flushed:

It is possible from node, but you’ll have to call from javascript web3 library a specific smart contract function in order to generate a transaction that will be sent to a speedy node in order to make that transfer on blockchain.

Hmmmmm now I’m even more :confused: lol

Something like what you see here: https://youtu.be/rd0TTLjQLy4?t=1247 in order to call a particular smart contract function, this example is not for ERC-1155.