Skip to content

Instantly share code, notes, and snippets.

Last active June 18, 2021 10:29
What would you like to do?
Sending a tx in filecoin w/ extra data

Messages in Filecoin allow sending arbitrary values through the params field.

Encoding data into params

  • data to send through transactions should be base64 encoded when using the message sending APIs.
  • note: you'll be sending to method: 0, which should be the default in your tools. method: 0 will ignore the params.

lotus-shed example

  • assuming you have a configured lotus and lotus-shed
  • assuming the data you want to send is aGVsbG8= (base64. or in hex: 68656c6c6f)
./lotus-shed rpc MpoolPushMessage '[{"From":"f3u27vs6zd3eesaevkawq4wo3emr45vu7cipjkbi5zgafko32aoebqikw7ohgsirdsenvsp73z6doogpoinwhq", "To": "f3wnmzhu5iln7shuawotkmbaejf6oabp7dits4t4p6zvwxeomqgewjpmp4ho4oyuxuga2gzwe7eu2nmw4prsjq", "Value": "1", "Params": "aGVsbG8="}, {"MaxFee": "70000000000000000"}]'


lotus API example

  • TODO: show an example here of signing the message outside, and using MPoolPush

filecoin.js example

  • using filecoin.js, assuming you have set it up (see their docs)
  • you should be able to do something like this:
const msgVals = {
    To: <to-addr>,
    From: <from-addr>,
    Value: new BigNumber(<amount>),
    Params: <base64-encoded-params>, // todo: check if this is base64 encoded string, or a Buffer

const message = await walletProvider.createMessage(msgVals);
const signedMessage = await walletProvider.signMessage(message);
const msgCid = await walletProvider.sendSignedMessage(signedMessage);

js-lotus-client example

  • TODO: write an example w/ js-lotus-client

filecoin-signing-tools example

Hosted services

there are a bunch of filecoin node hosted services. see:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment