Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

X and Y genes in the Ronin blockchain #10

Closed
herenickname opened this issue Sep 16, 2021 · 4 comments
Closed

X and Y genes in the Ronin blockchain #10

herenickname opened this issue Sep 16, 2021 · 4 comments

Comments

@herenickname
Copy link

herenickname commented Sep 16, 2021

Hello, at the moment I am analyzing the Ronin blockchain and cannot figure out how the axie body parts and genes can be decoded.

The code I ran:

import Web3 from 'web3'

const web3 = new Web3('https://api.roninchain.com/rpc')
const axieContract = new web3.eth.Contract(ABI, axieContractAddress)

axieContract.methods.axie(4950464).call().then(console.log)

RPC Response:

Result {
  '0': '4428344',
  '1': '4505689',
  '2': '1629870871',
  '3': [
    '14474011154664526034939695189344445127921630876185289334580322480553868674050',
    '1766957471863971104923304451713139065230110618240613685279804305648419844',
    x: '14474011154664526034939695189344445127921630876185289334580322480553868674050',
    y: '1766957471863971104923304451713139065230110618240613685279804305648419844'
  ],
  '4': '2',
  '5': '0',
  sireId: '4428344',
  matronId: '4505689',
  birthDate: '1629870871',
  genes: [
    '14474011154664526034939695189344445127921630876185289334580322480553868674050',
    '1766957471863971104923304451713139065230110618240613685279804305648419844',
    x: '14474011154664526034939695189344445127921630876185289334580322480553868674050',
    y: '1766957471863971104923304451713139065230110618240613685279804305648419844'
  ],
  breedCount: '2',
  level: '0'
}

Can your library help me get genes for the genes.x and genes.y I have?
Do you have any idea how to convert this to the SHA hash your library needs?

@herenickname
Copy link
Author

I tried to concatenate the X and Y gene strings, but nothing was happened.

const axieState = await axieContract.methods.axie(4950464).call()
const sha512 = crypto
        .createHash('sha512')
        .update(axieState.genes.x + axieState.genes.y)
        .digest('hex')
const axieGene = new AxieGene(sha512, HexType.Bit512)

Error: cannot recognize class

@ShaneMaglangit
Copy link
Owner

ShaneMaglangit commented Sep 16, 2021

Ensure that the sha512 value that you're passing is a string of hex prefixed with 0x

@herenickname
Copy link
Author

herenickname commented Sep 16, 2021

Ensure that the sha512 value that you're passing is a string of hex prefixed with 0x

Generated sha512 string is not contain '0x' prefix, anyway, your parser will remove it.
https://github.com/ShaneMaglangit/agp-npm/blob/main/src/axie-gene.ts#L179

@herenickname
Copy link
Author

herenickname commented Sep 16, 2021

I found the answer, here is it:

const axieState = await axieContract.methods.axie(4950464).call()

const x = BigInt(axieState.genes.x).toString(2).padStart(256, '0')
const y = BigInt(axieState.genes.y).toString(2).padStart(256, '0')
const z = BigInt('0b' + (x + y)).toString(16)

const axieGene = new AxieGene(z, HexType.Bit512)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants