Skip to content

Instantly share code, notes, and snippets.

@0xAshish
Last active November 26, 2019 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xAshish/0dddb57f7c8f9c9d0fdffd535893e57b to your computer and use it in GitHub Desktop.
Save 0xAshish/0dddb57f7c8f9c9d0fdffd535893e57b to your computer and use it in GitHub Desktop.
import Web3 from 'web3'
// contract abi
import * as Ring from './abi/ring.json'
import * as Item from './abi/item.json'
import * as Unit from './abi/Unit.json'
const addresses = [
'0x972e633f5f6f62d1f2a13977f113941fcb3b606b',
'0x5c4eab549a528bf15c47a01e174500010997235c',
'0xf0fc268473a4ffaf2a652c3a8510bf79b787a68f',
]
const API_KEY = ``
const PRIV_KEY = ``
let main = async function() {
// mainnet provider
let web3 = new Web3(`https://mainnet.infura.io/v3/${API_KEY}`)
// matic provider
let web3Child = new Web3('https://testnet2.matic.network')
// mainnet contract
let CBU = new web3.eth.Contract(
Unit.abi,
'0x23766996636058b41a041d441ce1217c694f5aa9'
)
// matic contract
let CBUChild = new web3Child.eth.Contract(
Unit.abi,
'0x20Cf76B0C99B3a3EF14c813d016D46d9F9eB599A'
)
for (let i = 0; i < addresses.length; i++) {
let key = addresses[i]
let N = await CBU.methods.balanceOf(key).call()
for (let j = 0; j < N; j++) {
const tokenId = await CBU.methods.tokenOfOwnerByIndex(key, j).call()
const _classId = await CBU.methods.getUnitById(tokenId).call()
const txObj = CBUChild.methods.mintUnitFromServer(_classId.dataId, key)
const encodedABI = txObj.encodeABI()
console.log('mintUnitFromServer', _classId.dataId, key)
const tx = {
from: '0xB0AcBFdb874d04E91B8087C2BcDa147b96d63c01',
to: '0x20Cf76B0C99B3a3EF14c813d016D46d9F9eB599A',
gas: 8000000,
data: encodedABI,
}
const signedTx = await web3Child.eth.accounts.signTransaction(
tx,
PRIV_KEY
)
const receipt = await web3Child.eth.sendSignedTransaction(
signedTx.rawTransaction
)
console.log(receipt.transactionHash)
}
}
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment